31 lines
815 B
Python
31 lines
815 B
Python
import nacl.bindings
|
|
from nacl.public import PublicKey
|
|
from nacl.signing import VerifyKey
|
|
|
|
from rainbowadn.inlining import *
|
|
|
|
__all__ = ('Subject',)
|
|
|
|
|
|
class Subject(IAtomic):
|
|
def __init__(self, verify_key: VerifyKey):
|
|
assert isinstance(verify_key, VerifyKey)
|
|
self.verify_key: VerifyKey = verify_key
|
|
self.public_key: PublicKey = verify_key.to_curve25519_public_key()
|
|
assert isinstance(self.public_key, PublicKey)
|
|
|
|
@classmethod
|
|
def size(cls) -> int:
|
|
return nacl.bindings.crypto_sign_PUBLICKEYBYTES
|
|
|
|
@classmethod
|
|
def _from_bytes(cls, source: bytes) -> 'Subject':
|
|
assert isinstance(source, bytes)
|
|
return cls(VerifyKey(source))
|
|
|
|
def __bytes__(self):
|
|
return bytes(self.verify_key)
|
|
|
|
def __str__(self):
|
|
return f'(subject)'
|