Add serialization/deserialization methods for Capsule

Fix names
pull/15/head
tuxxy 2018-01-15 15:45:24 -07:00
parent 444800a919
commit 632538707c
1 changed files with 24 additions and 0 deletions

View File

@ -122,6 +122,27 @@ class Capsule(object):
self.cfrags = {}
@classmethod
def from_bytes(self, data: bytes, curve):
"""
Instantiates a Capsule object from the serialized data.
"""
eph_e = Point.from_bytes(data[0:33], curve)
eph_v = Point.from_bytes(data[33:66], curve)
sig = BigNum.from_bytes(data[66:98], curve)
return Capsule(eph_e, eph_v, sig)
def to_bytes(self):
"""
Serialize the Capsule into a bytestring.
"""
eph_e = self.point_eph_e.to_bytes()
eph_v = self.point_eph_v.to_bytes()
sig = self.bn_sig.to_bytes()
return eph_e + eph_v + sig
def verify(self, params: UmbralParameters):
e = self.point_eph_e
@ -153,6 +174,9 @@ class Capsule(object):
return ReconstructedCapsule(e_prime=e, v_prime=v, x=cfrag_0.point_eph_ni)
def __bytes__(self):
self.to_bytes()
class ReconstructedCapsule(object):
def __init__(self, e_prime, v_prime, x):