InstanceReference.vala 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. namespace LibPeer.Protocols.Mx2 {
  2. public class InstanceReference {
  3. public uint8[] verification_key { get; private set; }
  4. public uint8[] public_key { get; private set; }
  5. public InstanceReference(uint8[] verification_key, uint8[] public_key)
  6. requires (verification_key.length == 32)
  7. requires (public_key.length == 32)
  8. {
  9. this.verification_key = verification_key;
  10. this.public_key = public_key;
  11. }
  12. public InstanceReference.from_stream(InputStream stream) throws IOError {
  13. verification_key = new uint8[32];
  14. stream.read(_verification_key);
  15. public_key = new uint8[32];
  16. stream.read(public_key);
  17. }
  18. public void serialise(OutputStream stream) throws IOError {
  19. stream.write(verification_key);
  20. stream.write(public_key);
  21. }
  22. private Bytes combined_bytes () {
  23. uint8[] combined = new Util.ByteComposer()
  24. .add_byte_array(verification_key)
  25. .add_byte_array(public_key)
  26. .to_byte_array();
  27. return new Bytes(combined);
  28. }
  29. public uint hash() {
  30. return combined_bytes().hash();
  31. }
  32. public int compare(InstanceReference other) {
  33. return combined_bytes().compare(other.combined_bytes());
  34. }
  35. }
  36. }