Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark size constants as ClassVars #729

Merged
merged 1 commit into from Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/nacl/public.py
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
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