Skip to content

Commit c32401a

Browse files
committed
x509-cert: builder: make keyEncipherment usage optional
ECDSA keys can not be used for keyEncipherment. Make this keyUsage bit optional. Signed-off-by: Dmitry Baryshkov <[email protected]>
1 parent 54e18d1 commit c32401a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

x509-cert/src/builder.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ pub enum Profile {
9090
issuer: Name,
9191
/// should the key agreement flag of KeyUsage be enabled
9292
enable_key_agreement: bool,
93+
/// should the key encipherment flag of KeyUsage be enabled
94+
enable_key_encipherment: bool,
9395
},
9496
#[cfg(feature = "hazmat")]
9597
/// Opt-out of the default extensions
@@ -169,11 +171,13 @@ impl Profile {
169171
}
170172
Profile::Leaf {
171173
enable_key_agreement,
174+
enable_key_encipherment,
172175
..
173176
} => {
174-
let mut key_usage = KeyUsages::DigitalSignature
175-
| KeyUsages::NonRepudiation
176-
| KeyUsages::KeyEncipherment;
177+
let mut key_usage = KeyUsages::DigitalSignature | KeyUsages::NonRepudiation;
178+
if *enable_key_encipherment {
179+
key_usage |= KeyUsages::KeyEncipherment;
180+
}
177181
if *enable_key_agreement {
178182
key_usage |= KeyUsages::KeyAgreement;
179183
}

x509-cert/tests/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ fn leaf_certificate() {
116116
let profile = Profile::Leaf {
117117
issuer,
118118
enable_key_agreement: false,
119+
enable_key_encipherment: false,
119120
};
120121

121122
let subject = Name::from_str("CN=service.domination.world")

0 commit comments

Comments
 (0)