Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F8391803
test_EC_compat.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
test_EC_compat.py
View Options
import
pytest
try
:
from
jose.backends.cryptography_backend
import
CryptographyECKey
from
jose.backends.ecdsa_backend
import
ECDSAECKey
except
ImportError
:
ECDSAECKey
=
CryptographyECKey
=
None
from
jose.constants
import
ALGORITHMS
from
.test_EC
import
private_key
@pytest.mark.backend_compatibility
@pytest.mark.skipif
(
None
in
(
ECDSAECKey
,
CryptographyECKey
),
reason
=
"Multiple crypto backends not available for backend compatibility tests"
,
)
class
TestBackendEcdsaCompatibility
:
@pytest.mark.parametrize
(
"BackendSign"
,
[
ECDSAECKey
,
CryptographyECKey
])
@pytest.mark.parametrize
(
"BackendVerify"
,
[
ECDSAECKey
,
CryptographyECKey
])
def
test_signing_parity
(
self
,
BackendSign
,
BackendVerify
):
key_sign
=
BackendSign
(
private_key
,
ALGORITHMS
.
ES256
)
key_verify
=
BackendVerify
(
private_key
,
ALGORITHMS
.
ES256
)
.
public_key
()
msg
=
b
"test"
sig
=
key_sign
.
sign
(
msg
)
# valid signature
assert
key_verify
.
verify
(
msg
,
sig
)
# invalid signature
assert
not
key_verify
.
verify
(
msg
,
b
"n"
*
64
)
@pytest.mark.parametrize
(
"BackendFrom"
,
[
ECDSAECKey
,
CryptographyECKey
])
@pytest.mark.parametrize
(
"BackendTo"
,
[
ECDSAECKey
,
CryptographyECKey
])
def
test_public_key_to_pem
(
self
,
BackendFrom
,
BackendTo
):
key
=
BackendFrom
(
private_key
,
ALGORITHMS
.
ES256
)
key2
=
BackendTo
(
private_key
,
ALGORITHMS
.
ES256
)
assert
key
.
public_key
()
.
to_pem
()
.
strip
()
==
key2
.
public_key
()
.
to_pem
()
.
strip
()
@pytest.mark.parametrize
(
"BackendFrom"
,
[
ECDSAECKey
,
CryptographyECKey
])
@pytest.mark.parametrize
(
"BackendTo"
,
[
ECDSAECKey
,
CryptographyECKey
])
def
test_private_key_to_pem
(
self
,
BackendFrom
,
BackendTo
):
key
=
BackendFrom
(
private_key
,
ALGORITHMS
.
ES256
)
key2
=
BackendTo
(
private_key
,
ALGORITHMS
.
ES256
)
assert
key
.
to_pem
()
.
strip
()
==
key2
.
to_pem
()
.
strip
()
@pytest.mark.parametrize
(
"BackendFrom"
,
[
ECDSAECKey
,
CryptographyECKey
])
@pytest.mark.parametrize
(
"BackendTo"
,
[
ECDSAECKey
,
CryptographyECKey
])
def
test_public_key_load_cycle
(
self
,
BackendFrom
,
BackendTo
):
key
=
BackendFrom
(
private_key
,
ALGORITHMS
.
ES256
)
pubkey
=
key
.
public_key
()
pub_pem_source
=
pubkey
.
to_pem
()
.
strip
()
pub_target
=
BackendTo
(
pub_pem_source
,
ALGORITHMS
.
ES256
)
assert
pub_pem_source
==
pub_target
.
to_pem
()
.
strip
()
@pytest.mark.parametrize
(
"BackendFrom"
,
[
ECDSAECKey
,
CryptographyECKey
])
@pytest.mark.parametrize
(
"BackendTo"
,
[
ECDSAECKey
,
CryptographyECKey
])
def
test_private_key_load_cycle
(
self
,
BackendFrom
,
BackendTo
):
key
=
BackendFrom
(
private_key
,
ALGORITHMS
.
ES256
)
pem_source
=
key
.
to_pem
()
.
strip
()
target
=
BackendTo
(
pem_source
,
ALGORITHMS
.
ES256
)
assert
pem_source
==
target
.
to_pem
()
.
strip
()
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Jun 4 2025, 6:50 PM (12 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3306070
Attached To
rPJOS python3-jose
Event Timeline
Log In to Comment