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

22 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-08 06:05 +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.primitives.asymmetric import dh 

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

11 PrivateKeyTypes, 

12 PublicKeyTypes, 

13) 

14 

15 

16def load_pem_private_key( 

17 data: bytes, 

18 password: typing.Optional[bytes], 

19 backend: typing.Any = None, 

20 *, 

21 unsafe_skip_rsa_key_validation: bool = False, 

22) -> PrivateKeyTypes: 

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

24 

25 return ossl.load_pem_private_key( 

26 data, password, unsafe_skip_rsa_key_validation 

27 ) 

28 

29 

30def load_pem_public_key( 

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

32) -> PublicKeyTypes: 

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

34 

35 return ossl.load_pem_public_key(data) 

36 

37 

38def load_pem_parameters( 

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

40) -> dh.DHParameters: 

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

42 

43 return ossl.load_pem_parameters(data) 

44 

45 

46def load_der_private_key( 

47 data: bytes, 

48 password: typing.Optional[bytes], 

49 backend: typing.Any = None, 

50 *, 

51 unsafe_skip_rsa_key_validation: bool = False, 

52) -> PrivateKeyTypes: 

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

54 

55 return ossl.load_der_private_key( 

56 data, password, unsafe_skip_rsa_key_validation 

57 ) 

58 

59 

60def load_der_public_key( 

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

62) -> PublicKeyTypes: 

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

64 

65 return ossl.load_der_public_key(data) 

66 

67 

68def load_der_parameters( 

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

70) -> dh.DHParameters: 

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

72 

73 return ossl.load_der_parameters(data)