Ejemplo n.º 1
0
 def test_sample_rfc8392_a6_with_encoding(self):
     sig_key = COSEKey.from_bytes(bytes.fromhex(SAMPLE_COSE_KEY_RFC8392_A2_3))
     signed = cwt.encode(
         {
             1: "coap://as.example.com",
             2: "erikw",
             3: "coap://light.example.com",
             4: 1444064944,
             5: 1443944944,
             6: 1443944944,
             7: bytes.fromhex("0b71"),
         },
         key=sig_key,
     )
     enc_key = COSEKey.from_bytes(bytes.fromhex(SAMPLE_COSE_KEY_RFC8392_A2_1))
     nonce = bytes.fromhex("4a0694c0e69ee6b5956655c7b2")
     encrypted = cwt.encode(signed, key=enc_key, nonce=nonce)
     decoded = cwt.decode(encrypted, keys=[enc_key, sig_key], no_verify=True)
     assert 1 in decoded and decoded[1] == "coap://as.example.com"
Ejemplo n.º 2
0
 def test_sample_rfc8392_a3(self):
     key = COSEKey.from_bytes(bytes.fromhex(SAMPLE_COSE_KEY_RFC8392_A2_3))
     encoded = bytes.fromhex(SAMPLE_CWT_RFC8392_A3)
     decoded = cwt.decode(encoded, keys=key, no_verify=True)
     assert 1 in decoded and decoded[1] == "coap://as.example.com"
     assert 2 in decoded and decoded[2] == "erikw"
     assert 3 in decoded and decoded[3] == "coap://light.example.com"
     assert 4 in decoded and decoded[4] == 1444064944
     assert 5 in decoded and decoded[5] == 1443944944
     assert 6 in decoded and decoded[6] == 1443944944
     assert 7 in decoded and decoded[7] == bytes.fromhex("0b71")
Ejemplo n.º 3
0
 def test_sample_rfc8392_a3_with_encoding(self):
     key = COSEKey.from_bytes(bytes.fromhex(SAMPLE_COSE_KEY_RFC8392_A2_3))
     token = cwt.encode(
         {
             1: "coap://as.example.com",
             2: "erikw",
             3: "coap://light.example.com",
             4: 1444064944,
             5: 1443944944,
             6: 1443944944,
             7: bytes.fromhex("0b71"),
         },
         key,
     )
     decoded = cwt.decode(token, keys=key, no_verify=True)
     assert 1 in decoded and decoded[1] == "coap://as.example.com"
Ejemplo n.º 4
0
 def test_sample_rfc8392_a5(self):
     key = COSEKey.from_bytes(bytes.fromhex(SAMPLE_COSE_KEY_RFC8392_A2_1))
     nonce = bytes.fromhex("99a0d7846e762c49ffe8a63e0b")
     token = cwt.encode(
         {
             1: "coap://as.example.com",
             2: "erikw",
             3: "coap://light.example.com",
             4: 1444064944,
             5: 1443944944,
             6: 1443944944,
             7: bytes.fromhex("0b71"),
         },
         key=key,
         nonce=nonce,
     )
     assert token == bytes.fromhex(SAMPLE_CWT_RFC8392_A5)
     decoded = cwt.decode(token, keys=key, no_verify=True)
     assert 1 in decoded and decoded[1] == "coap://as.example.com"
Ejemplo n.º 5
0
 def test_sample_rfc8392_a6(self):
     sig_key = COSEKey.from_bytes(bytes.fromhex(SAMPLE_COSE_KEY_RFC8392_A2_3))
     enc_key = COSEKey.from_bytes(bytes.fromhex(SAMPLE_COSE_KEY_RFC8392_A2_1))
     encrypted = bytes.fromhex(SAMPLE_CWT_RFC8392_A6)
     decoded = cwt.decode(encrypted, keys=[enc_key, sig_key], no_verify=True)
     assert 1 in decoded and decoded[1] == "coap://as.example.com"