Skip to content

Commit

Permalink
Mark size constants as ClassVars (#729)
Browse files Browse the repository at this point in the history
I guess I wasn't looking out for this before since there weren't any
mypy errors. Nice to have though.
  • Loading branch information
DMRobertson committed Dec 23, 2021
1 parent 1d44ed1 commit 3f34a25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/nacl/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Generic, Optional, Type, TypeVar
from typing import ClassVar, Generic, Optional, Type, TypeVar

import nacl.bindings
from nacl import encoding
Expand All @@ -31,7 +31,7 @@ class PublicKey(encoding.Encodable, StringFixer):
:cvar SIZE: The size that the public key is required to be
"""

SIZE = nacl.bindings.crypto_box_PUBLICKEYBYTES
SIZE: ClassVar[int] = nacl.bindings.crypto_box_PUBLICKEYBYTES

def __init__(
self,
Expand Down Expand Up @@ -81,8 +81,8 @@ class PrivateKey(encoding.Encodable, StringFixer):
private key is required to be
"""

SIZE = nacl.bindings.crypto_box_SECRETKEYBYTES
SEED_SIZE = nacl.bindings.crypto_box_SEEDBYTES
SIZE: ClassVar[int] = nacl.bindings.crypto_box_SECRETKEYBYTES
SEED_SIZE: ClassVar[int] = nacl.bindings.crypto_box_SEEDBYTES

def __init__(
self,
Expand Down Expand Up @@ -190,7 +190,7 @@ class Box(encoding.Encodable, StringFixer):
:cvar NONCE_SIZE: The size that the nonce is required to be.
"""

NONCE_SIZE = nacl.bindings.crypto_box_NONCEBYTES
NONCE_SIZE: ClassVar[int] = nacl.bindings.crypto_box_NONCEBYTES
_shared_key: bytes

def __init__(self, private_key: PrivateKey, public_key: PublicKey):
Expand Down
12 changes: 7 additions & 5 deletions src/nacl/secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Optional
from typing import ClassVar, Optional

import nacl.bindings
from nacl import encoding
Expand Down Expand Up @@ -49,10 +49,12 @@ class SecretBox(encoding.Encodable, StringFixer):
pair.
"""

KEY_SIZE = nacl.bindings.crypto_secretbox_KEYBYTES
NONCE_SIZE = nacl.bindings.crypto_secretbox_NONCEBYTES
MACBYTES = nacl.bindings.crypto_secretbox_MACBYTES
MESSAGEBYTES_MAX = nacl.bindings.crypto_secretbox_MESSAGEBYTES_MAX
KEY_SIZE: ClassVar[int] = nacl.bindings.crypto_secretbox_KEYBYTES
NONCE_SIZE: ClassVar[int] = nacl.bindings.crypto_secretbox_NONCEBYTES
MACBYTES: ClassVar[int] = nacl.bindings.crypto_secretbox_MACBYTES
MESSAGEBYTES_MAX: ClassVar[
int
] = nacl.bindings.crypto_secretbox_MESSAGEBYTES_MAX

def __init__(
self, key: bytes, encoder: encoding.Encoder = encoding.RawEncoder
Expand Down

0 comments on commit 3f34a25

Please sign in to comment.