[ Avaa Bypassed ]




Upload:

Command:

www-data@3.143.211.215: ~ $
# Copyright 2017 Canonical Ltd.
# Licensed under the LGPLv3, see LICENCE file for details.

import nacl.public


class PrivateKey(object):
    ''' A private key used by the bakery to encrypt and decrypt
    third party caveats.
    Internally, it is a 256-bit Ed25519 private key.
    '''
    def __init__(self, key):
        self._key = key

    @property
    def key(self):
        ''' Internal nacl key representation.
        '''
        return self._key

    @property
    def public_key(self):
        '''
        :return: the PublicKey associated with the private key.
        '''
        return PublicKey(self._key.public_key)

    @classmethod
    def deserialize(cls, serialized):
        ''' Create a PrivateKey from a base64 encoded bytes.
        :return: a PrivateKey
        '''
        return PrivateKey(
            nacl.public.PrivateKey(serialized,
                                   encoder=nacl.encoding.Base64Encoder))

    def serialize(self, raw=False):
        '''Encode the private part of the key in a base64 format by default,
        but when raw is True it will return hex encoded bytes.
        @return: bytes
        '''
        if raw:
            return self._key.encode()
        return self._key.encode(nacl.encoding.Base64Encoder)

    def __str__(self):
        '''Return the private part of the key key as a base64-encoded string'''
        return self.serialize().decode('utf-8')

    def __eq__(self, other):
        return self.key == other.key


class PublicKey(object):
    ''' A public key used by the bakery to encrypt third party caveats.

    Every discharger is associated with a public key which is used to
    encrypt third party caveat ids addressed to that discharger.
    Internally, it is a 256 bit Ed25519 public key.
    '''
    def __init__(self, key):
        self._key = key

    @property
    def key(self):
        ''' Internal nacl key representation.
        '''
        return self._key

    def serialize(self, raw=False):
        '''Encode the private part of the key in a base64 format by default,
        but when raw is True it will return hex encoded bytes.
        @return: bytes
        '''
        if raw:
            return self._key.encode()
        return self._key.encode(nacl.encoding.Base64Encoder)

    def __str__(self):
        '''Return the key as a base64-encoded string'''
        return self.serialize().decode('utf-8')

    @classmethod
    def deserialize(cls, serialized):
        ''' Create a PublicKey from a base64 encoded bytes.
        :return: a PublicKey
        '''
        return PublicKey(
            nacl.public.PublicKey(serialized,
                                  encoder=nacl.encoding.Base64Encoder))

    def __eq__(self, other):
        return self.key == other.key


def generate_key():
    '''GenerateKey generates a new PrivateKey.
    :return: a PrivateKey
    '''
    return PrivateKey(nacl.public.PrivateKey.generate())

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
_internal Folder 0755
__init__.py File 2.62 KB 0644
_authorizer.py File 4.01 KB 0644
_bakery.py File 3.13 KB 0644
_checker.py File 16.33 KB 0644
_codec.py File 10.2 KB 0644
_discharge.py File 9.16 KB 0644
_error.py File 2.26 KB 0644
_identity.py File 4.05 KB 0644
_keys.py File 2.87 KB 0644
_macaroon.py File 15.18 KB 0644
_oven.py File 10.39 KB 0644
_store.py File 2.24 KB 0644
_third_party.py File 2.01 KB 0644
_versions.py File 176 B 0644