示例#1
0
 def test_load_typecheck(self):
     ''' Test type checking on load. Added in case load starts to use
     its own type checking.
     '''
     mv = memoryview(self.alice.private)
     with self.assertRaises(TypeError, msg='PrivateKey failed init type check.'):
         alice = PrivateKey.load(mv)
     ba = bytearray(self.alice.private)
     with self.assertRaises(TypeError, msg='PrivateKey failed init type check.'):
         alice = PrivateKey.load(ba)
     other = int.from_bytes(TVa, byteorder='big')
     with self.assertRaises(TypeError, msg='PrivateKey failed init type check.'):
         alice = PrivateKey.load(other)
示例#2
0
 def test_load_lencheck(self):
     ''' Test length checking on init. Added in case load starts to 
     use its own length checking.
     '''
     less = bytes(31)
     with self.assertRaises(ValueError, msg='PrivateKey failed init len check.'):
         test = PrivateKey.load(less)
         
     more = bytes(33)
     with self.assertRaises(ValueError, msg='PrivateKey failed init len check.'):
         test = PrivateKey.load(more)
         
     edge = bytes()
     with self.assertRaises(ValueError, msg='PrivateKey failed init len check.'):
         test = PrivateKey.load(edge)
示例#3
0
 def test_load(self):
     alice = self.alice.private
     bob = self.bob.private
     
     reloada = PrivateKey.load(alice)
     reloadb = PrivateKey.load(bob)
     
     self.assertEqual(
         self.alice.private,
         reloada.private,
         'Alice private key loading failed equality check.'
     )
     
     self.assertEqual(
         self.bob.private,
         reloadb.private,
         'Bob private key loading failed equality check.'
     )
示例#4
0
    def _from_serialized(cls, condensed):
        try:
            ghid = Ghid.from_bytes(condensed['ghid'])
            keys = {
                'signature':
                serialization.load_der_private_key(data=condensed['signature'],
                                                   password=None,
                                                   backend=CRYPTO_BACKEND),
                'encryption':
                serialization.load_der_private_key(
                    data=condensed['encryption'],
                    password=None,
                    backend=CRYPTO_BACKEND),
                'exchange':
                ECDHPrivate.load(condensed['exchange'])
            }
        except (TypeError, KeyError) as e:
            raise TypeError(
                'serialization must be compatible with _serialize.') from e

        return cls(keys=keys, ghid=ghid)
示例#5
0
 def _from_serialized(cls, condensed):
     try:
         ghid = Ghid.from_bytes(condensed['ghid'])
         keys = {
             'signature': serialization.load_der_private_key(
                 data = condensed['signature'],
                 password = None,
                 backend = CRYPTO_BACKEND
             ),
             'encryption': serialization.load_der_private_key(
                 data = condensed['encryption'],
                 password = None,
                 backend = CRYPTO_BACKEND
             ),
             'exchange': ECDHPrivate.load(condensed['exchange'])
         }
     except (TypeError, KeyError) as e:
         raise TypeError(
             'serialization must be compatible with _serialize.'
         ) from e
         
     return cls(keys=keys, ghid=ghid)