コード例 #1
0
ファイル: test_signedjson.py プロジェクト: rr4/laniakea
    def test_sign_and_verify(self):
        assert 'signatures' in self.signed
        assert 'Alice' in self.signed['signatures']
        assert 'mock:test' in self.signed['signatures']['Alice']
        assert self.signed['signatures']['Alice']['mock:test'] == encode_base64(b'x_______')

        assert self.sigkey.signed_bytes == b'{"foo":"bar"}'
        verify_signed_json(self.signed, 'Alice', self.verkey)
コード例 #2
0
def verify_event_message(sender, event, key, assume_valid=False):
    '''
    Verify the validity of this event, via its required fields as
    well as cryptographical signature.
    '''
    if not assume_valid:
        if not event_message_is_valid_and_signed(event):
            raise Exception('Message was not valid or not signed.')

    if type(key) is str:
        key = decode_verify_key_bytes(NACL_ED25519 + ':' + '0',
                                      decode_base64(key))

    verify_signed_json(event, sender,
                       key)  # this will raise an error if validation fails
コード例 #3
0
ファイル: test_signedjson.py プロジェクト: rr4/laniakea
 def test_verify_fail_not_base64(self):
     invalid = {'signatures': {'Alice': {'mock:test': 'not base64'}}}
     with pytest.raises(SignatureVerifyException):
         verify_signed_json(invalid, 'Alice', self.verkey)
コード例 #4
0
ファイル: test_signedjson.py プロジェクト: rr4/laniakea
 def test_verify_fail_no_signature_for_alice(self):
     with pytest.raises(SignatureVerifyException):
         verify_signed_json({'signatures': {}}, 'Alice', self.verkey)
コード例 #5
0
ファイル: test_signedjson.py プロジェクト: rr4/laniakea
 def test_verify_fail(self):
     self.signed['signatures']['Alice']['mock:test'] = encode_base64(
         b'not a signature'
     )
     with pytest.raises(SignatureVerifyException):
         verify_signed_json(self.signed, 'Alice', self.verkey)