mirror of https://github.com/nucypher/pyUmbral.git
parent
444800a919
commit
632538707c
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue