1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//! ## Usage
//!
//! ### Borrowed DER decoding
//!
//! [`RsaPrivateKeyRef`] and [`RsaPublicKeyRef`] borrow their integer data from the input.
//! Import [`der::Decode`] to use `from_der`:
//!
//! ```rust
//! use pkcs1::{RsaPrivateKeyRef, der::Decode};
//!
//! # let der = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/examples/rsa2048-priv.der"));
//! let key = RsaPrivateKeyRef::from_der(der)?;
//! # Ok::<(), pkcs1::Error>(())
//! ```
//!
//! Here, `der` is a byte slice containing a PKCS#1 DER-encoded private key.
//! `RsaPrivateKeyRef::try_from(der)` also decodes DER when `der` has type `&[u8]`.
//! Both methods are available without enabling any features.
//!
//! ### Owned DER decoding and encoding
//!
//! Enable the `alloc` feature to use [`RsaPrivateKeyOwned`] and [`RsaPublicKeyOwned`].
//! These types own their integer data and implement [`DecodeRsaPrivateKey`] and
//! [`DecodeRsaPublicKey`], respectively:
//!
//! ```rust
//! # #[cfg(feature = "alloc")]
//! # {
//! use pkcs1::{DecodeRsaPrivateKey, EncodeRsaPrivateKey, RsaPrivateKeyOwned};
//!
//! # let der = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/examples/rsa2048-priv.der"));
//! let key = RsaPrivateKeyOwned::from_pkcs1_der(der)?;
//! let document = key.to_pkcs1_der()?;
//! assert_eq!(document.as_bytes(), der);
//! # }
//! # Ok::<(), pkcs1::Error>(())
//! ```
//!
//! [`EncodeRsaPrivateKey`] and [`EncodeRsaPublicKey`] support both borrowed and owned keys.
//! The decoding traits require owned results; use [`der::Decode`] for the borrowed types as shown
//! above. RSA implementations can also implement these traits for their own key types.
//!
//! ### PEM decoding and encoding
//!
//! Enable the `pem` feature (which also enables `alloc`) to use `from_pkcs1_pem` and
//! `to_pkcs1_pem` with the PEM labels shown above:
//!
//! ```rust
//! # #[cfg(feature = "pem")]
//! # {
//! use pkcs1::{DecodeRsaPrivateKey, EncodeRsaPrivateKey, LineEnding, RsaPrivateKeyOwned};
//!
//! # let pem = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/examples/rsa2048-priv.pem"));
//! let key = RsaPrivateKeyOwned::from_pkcs1_pem(pem)?;
//! let encoded = key.to_pkcs1_pem(LineEnding::LF)?;
//! assert_eq!(encoded.as_str(), pem);
//! # }
//! # Ok::<(), pkcs1::Error>(())
//! ```
//!
//! Here, `pem` is a string containing a PEM-encoded RSA private key.
//!
//! For public keys, use `RsaPublicKeyOwned` with `DecodeRsaPublicKey` and `EncodeRsaPublicKey`
//! (the method names are the same).
extern crate alloc;
extern crate std;
pub use ;
pub use crate::;
pub use crate::;
pub use ;
/// `rsaEncryption` Object Identifier (OID)
pub const ALGORITHM_OID: ObjectIdentifier = new_unwrap;
/// `AlgorithmIdentifier` for RSA.
pub const ALGORITHM_ID: AlgorithmIdentifierRef = AlgorithmIdentifierRef ;