Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/cryptography/hazmat/primitives/serialization/base.py: 52%

21 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-08 07:26 +0000

1# This file is dual licensed under the terms of the Apache License, Version 

2# 2.0, and the BSD License. See the LICENSE file in the root of this repository 

3# for complete details. 

4 

5from __future__ import annotations 

6 

7import typing 

8 

9from cryptography.hazmat.bindings._rust import openssl as rust_openssl 

10from cryptography.hazmat.primitives.asymmetric import dh 

11from cryptography.hazmat.primitives.asymmetric.types import ( 

12 PrivateKeyTypes, 

13 PublicKeyTypes, 

14) 

15 

16 

17def load_pem_private_key( 

18 data: bytes, 

19 password: bytes | None, 

20 backend: typing.Any = None, 

21 *, 

22 unsafe_skip_rsa_key_validation: bool = False, 

23) -> PrivateKeyTypes: 

24 from cryptography.hazmat.backends.openssl.backend import backend as ossl 

25 

26 return ossl.load_pem_private_key( 

27 data, password, unsafe_skip_rsa_key_validation 

28 ) 

29 

30 

31def load_pem_public_key( 

32 data: bytes, backend: typing.Any = None 

33) -> PublicKeyTypes: 

34 from cryptography.hazmat.backends.openssl.backend import backend as ossl 

35 

36 return ossl.load_pem_public_key(data) 

37 

38 

39def load_pem_parameters( 

40 data: bytes, backend: typing.Any = None 

41) -> dh.DHParameters: 

42 return rust_openssl.dh.from_pem_parameters(data) 

43 

44 

45def load_der_private_key( 

46 data: bytes, 

47 password: bytes | None, 

48 backend: typing.Any = None, 

49 *, 

50 unsafe_skip_rsa_key_validation: bool = False, 

51) -> PrivateKeyTypes: 

52 from cryptography.hazmat.backends.openssl.backend import backend as ossl 

53 

54 return ossl.load_der_private_key( 

55 data, password, unsafe_skip_rsa_key_validation 

56 ) 

57 

58 

59def load_der_public_key( 

60 data: bytes, backend: typing.Any = None 

61) -> PublicKeyTypes: 

62 from cryptography.hazmat.backends.openssl.backend import backend as ossl 

63 

64 return ossl.load_der_public_key(data) 

65 

66 

67def load_der_parameters( 

68 data: bytes, backend: typing.Any = None 

69) -> dh.DHParameters: 

70 return rust_openssl.dh.from_der_parameters(data)