Пример #1
0
 def slughash(self) -> str:
     """
     Slug is long and not readable enough (given device_id is made of uuids).
     Hence it's often simpler to rely on it hash instead (e.g. select the
     device to use in the CLI by providing the beginning of the hash)
     """
     return blake2b(self.slug.encode()).hexdigest()
Пример #2
0
 def from_data(self, data: bytes) -> "HashDigest":
     ensure(
         isinstance(data, bytes) or isinstance(data, bytearray),
         "data type must be bytes or bytearray",
         raising=TypeError,
     )
     return HashDigest(blake2b(data if isinstance(data, bytes) else bytes(data)).digest())
Пример #3
0
def v2_encrypt(m, k, f=EMPTY, _n=None):
    h = V2_LOCAL
    if _n is not None:
        warnings.warn(EXPLICIT_NONCE_W, pexc.SecurityWarning)
        nk = _n
    else:
        nk = utils.random(24)
    n = hashlib.blake2b(m, digest_size=24, key=nk).digest()
    pre_auth = pae([h, n, f])
    c = sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(message=m,
                                                          aad=pre_auth,
                                                          nonce=n,
                                                          key=k)
    return _pack_msg(h, n + c, f)
Пример #4
0
 def root_verify_key_hash(self):
     return blake2b(self.root_verify_key.encode()).hexdigest()[:10]
Пример #5
0
 def slughash(self) -> str:
     return blake2b(self.slug.encode()).hexdigest()