mirror of
https://github.com/saymrwulf/cryptography.git
synced 2026-05-14 20:37:55 +00:00
Add initial CommonCrypto bindings (no backend yet)
This commit is contained in:
parent
1f15f890a3
commit
cc4a42dbc5
4 changed files with 144 additions and 0 deletions
12
cryptography/hazmat/bindings/commoncrypto/__init__.py
Normal file
12
cryptography/hazmat/bindings/commoncrypto/__init__.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# 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.
|
||||
40
cryptography/hazmat/bindings/commoncrypto/binding.py
Normal file
40
cryptography/hazmat/bindings/commoncrypto/binding.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# 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 __future__ import absolute_import, division, print_function
|
||||
|
||||
from cryptography.hazmat.bindings.utils import build_ffi
|
||||
|
||||
|
||||
class Binding(object):
|
||||
"""
|
||||
CommonCrypto API wrapper.
|
||||
"""
|
||||
_module_prefix = "cryptography.hazmat.bindings.commoncrypto."
|
||||
_modules = [
|
||||
"common_digest",
|
||||
]
|
||||
|
||||
ffi = None
|
||||
lib = None
|
||||
|
||||
def __init__(self):
|
||||
self._ensure_ffi_initialized()
|
||||
|
||||
@classmethod
|
||||
def _ensure_ffi_initialized(cls):
|
||||
if cls.ffi is not None and cls.lib is not None:
|
||||
return
|
||||
|
||||
cls.ffi, cls.lib = build_ffi(cls._module_prefix, cls._modules,
|
||||
"", "", [])
|
||||
67
cryptography/hazmat/bindings/commoncrypto/common_digest.py
Normal file
67
cryptography/hazmat/bindings/commoncrypto/common_digest.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# 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.
|
||||
|
||||
INCLUDES = """
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
"""
|
||||
|
||||
TYPES = """
|
||||
typedef uint32_t CC_LONG;
|
||||
typedef uint64_t CC_LONG64;
|
||||
typedef struct CC_MD5state_st {
|
||||
...;
|
||||
} CC_MD5_CTX;
|
||||
typedef struct CC_SHA1state_st {
|
||||
...;
|
||||
} CC_SHA1_CTX;
|
||||
typedef struct CC_SHA256state_st {
|
||||
...;
|
||||
} CC_SHA256_CTX;
|
||||
typedef struct CC_SHA512state_st {
|
||||
...;
|
||||
} CC_SHA512_CTX;
|
||||
"""
|
||||
|
||||
FUNCTIONS = """
|
||||
int CC_MD5_Init(CC_MD5_CTX *);
|
||||
int CC_MD5_Update(CC_MD5_CTX *, const void *, CC_LONG);
|
||||
int CC_MD5_Final(unsigned char *, CC_MD5_CTX *);
|
||||
|
||||
int CC_SHA1_Init(CC_SHA1_CTX *);
|
||||
int CC_SHA1_Update(CC_SHA1_CTX *, const void *, CC_LONG);
|
||||
int CC_SHA1_Final(unsigned char *, CC_SHA1_CTX *);
|
||||
|
||||
int CC_SHA224_Init(CC_SHA256_CTX *);
|
||||
int CC_SHA224_Update(CC_SHA256_CTX *, const void *, CC_LONG);
|
||||
int CC_SHA224_Final(unsigned char *, CC_SHA256_CTX *);
|
||||
|
||||
int CC_SHA256_Init(CC_SHA256_CTX *);
|
||||
int CC_SHA256_Update(CC_SHA256_CTX *, const void *, CC_LONG);
|
||||
int CC_SHA256_Final(unsigned char *, CC_SHA256_CTX *);
|
||||
|
||||
int CC_SHA384_Init(CC_SHA512_CTX *);
|
||||
int CC_SHA384_Update(CC_SHA512_CTX *, const void *, CC_LONG);
|
||||
int CC_SHA384_Final(unsigned char *, CC_SHA512_CTX *);
|
||||
|
||||
int CC_SHA512_Init(CC_SHA512_CTX *);
|
||||
int CC_SHA512_Update(CC_SHA512_CTX *, const void *, CC_LONG);
|
||||
int CC_SHA512_Final(unsigned char *, CC_SHA512_CTX *);
|
||||
"""
|
||||
|
||||
MACROS = """
|
||||
"""
|
||||
|
||||
CUSTOMIZATIONS = """
|
||||
"""
|
||||
|
||||
CONDITIONAL_NAMES = {}
|
||||
25
tests/hazmat/bindings/test_commoncrypto.py
Normal file
25
tests/hazmat/bindings/test_commoncrypto.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# 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.
|
||||
|
||||
import pytest
|
||||
|
||||
from cryptography.hazmat.bindings.commoncrypto.binding import Binding
|
||||
|
||||
|
||||
@pytest.mark.commoncrypto
|
||||
class TestCommonCrypto(object):
|
||||
def test_binding_loads(self):
|
||||
binding = Binding()
|
||||
assert binding
|
||||
assert binding.lib
|
||||
assert binding.ffi
|
||||
Loading…
Reference in a new issue