Esempio n. 1
0
def validate_asset_public_key(pk):
    pk_binary = pk['value'].encode('utf-8')
    decoder = get_public_key_decoder(pk)
    try:
        pk_decoded = decoder(pk_binary)
        if len(pk_decoded) != 32:
            raise InvalidPublicKey('Public key should be of size 32 bytes')

    except binascii.Error as e:
        raise InvalidPublicKey(
            'Invalid `type` specified for public key `value`')
Esempio n. 2
0
def get_public_key_decoder(pk):
    encoding = pk['type']
    decoder = base64.b64decode

    if encoding == 'ed25519-base16':
        decoder = base64.b16decode
    elif encoding == 'ed25519-base32':
        decoder = base64.b32decode
    elif encoding == 'ed25519-base64':
        decoder = base64.b64decode
    else:
        raise InvalidPublicKey(
            'Invalid `type` specified for public key `value`')

    return decoder