def test_rfc4231_3(self): key = b'\xaa' * 20 signer = HmacSha256Signer('name', key) data = b'\xdd' * 50 wire = bytearray(32) assert signer.write_signature_value(wire, [memoryview(data)]) == 32 assert wire.hex() == '773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe'
def test_rfc4231_2(self): key = b'Jefe' signer = HmacSha256Signer('name', key) data = b'what do ya want for nothing?' wire = bytearray(32) assert signer.write_signature_value(wire, [memoryview(data)]) == 32 assert wire.hex() == '5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843'
def test_data_1(self): key = bytes(i for i in range(32)) signer = HmacSha256Signer('key1', key) data = make_data('/ndn/abc', MetaInfo(None), b'SUCCESS!', signer) assert (data.hex() == '0649070a08036e646e0803616263' '140015085355434345535321' '160d1b01041c08070608046b657931' '172019868e7183998df373332f3dd1c9c950fc29d734c07977791d8396fa3b91fd36')
def test_rfc4231_1(self): key = b'\x0b' * 20 signer = HmacSha256Signer('name', key) data = b'Hi There' wire = bytearray(32) assert signer.get_signature_value_size() == 32 assert signer.write_signature_value(wire, [memoryview(data)]) == 32 assert wire.hex() == 'b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7'
def __init__(self, stype:SignatureType, keyName:Optional[str]=None, privKey:Optional[bytes]=None) -> None: self.type, self.signer, self.keyName, self.privKey = stype, None, "", b'' if self.type != SignatureType.DIGEST_SHA256 and self.type != SignatureType.NOT_SIGNED: if privKey is None or privKey == b'': raise KeyError("Private Key has to be Defined in Signing Info with this Type.") if keyName is None or keyName == "": raise KeyError("Key Name has to be Defined in Signing Info with this Type.") self.keyName = keyName self.privKey = privKey if self.type == SignatureType.SHA256_WITH_ECDSA: self.signer = Sha256WithEcdsaSigner(Name.from_str(self.keyName), self.privKey) elif self.type == SignatureType.SHA256_WITH_RSA: self.signer = Sha256WithRsaSigner(Name.from_str(self.keyName), self.privKey) elif self.type == SignatureType.HMAC_WITH_SHA256: self.signer = HmacSha256Signer(Name.from_str(self.keyName), self.privKey) elif self.type == SignatureType.DIGEST_SHA256: self.signer = DigestSha256Signer()