From 361e2c9a67da8c702474e0b4301c5ec612b56840 Mon Sep 17 00:00:00 2001 From: Donald Stufft <donald@stufft.io> Date: Sun, 17 Mar 2013 17:49:15 -0400 Subject: [PATCH] nacl.public.Box is not encodable * Removes the broken ability to encode a nacl.public.Box * Internal refactoring --- nacl/public.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/nacl/public.py b/nacl/public.py index 0f84a7b8..39e9c4f8 100644 --- a/nacl/public.py +++ b/nacl/public.py @@ -82,7 +82,7 @@ class PrivateKey(encoding.Encodable, six.StringFixer, object): ) -class Box(encoding.Encodable, six.StringFixer, object): +class Box(object): """ The Box class boxes and unboxes messages between a pair of keys @@ -105,12 +105,10 @@ class Box(encoding.Encodable, six.StringFixer, object): NONCE_SIZE = nacl.lib.crypto_box_NONCEBYTES def __init__(self, public_key, private_key): - self._pk = public_key._public_key - self._sk = private_key._private_key - self._shared_key = None + self._public_key = public_key + self._private_key = private_key - def __bytes__(self): - return self._sk + self._shared_key = None def encrypt(self, plaintext, nonce, encoder=encoding.RawEncoder): """ @@ -190,7 +188,11 @@ class Box(encoding.Encodable, six.StringFixer, object): k = nacl.ffi.new("unsigned char[]", sharedkey_size) - if not nacl.lib.crypto_box_beforenm(k, self._pk, self._sk): + if not nacl.lib.crypto_box_beforenm( + k, + self._public_key.encode(encoder=encoding.RawEncoder), + self._private_key.encode(encoder=encoding.RawEncoder), + ): raise CryptoError("Failed to derive shared key") self._shared_key = nacl.ffi.buffer(k, sharedkey_size)[:] -- GitLab