Skip to content

Commit 088f2da

Browse files
authored
sm2: fix compilation errors. (#1641)
Certain feature combinations in the sm2 crate currently cause compilation errors. This patch resolves the following issues: 1. dsa & pkcs8: * Fixed a mismatch where `Signature::ALGORITHM_IDENTIFIER` was gated behind `alloc`, even though the trait implementation did not require it. 2. pke: * Enabled the `pkcs8` feature by default when `pke` is active, as it depends on `pkcs8` support from the `elliptic-curve` and `der` crates. * Ensured `alloc` is enabled for `pke`, as encryption/decryption operations in `src/pke/decrypting.rs` and `encrypting.rs` return `Vec<u8>`. Cleaned up redundant feature gates in these files too.
1 parent cba0364 commit 088f2da

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

sm2/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ arithmetic = ["dep:primefield", "dep:primeorder", "elliptic-curve/arithmetic"]
4646
bits = ["arithmetic", "elliptic-curve/bits"]
4747
dsa = ["arithmetic", "dep:rfc6979", "dep:signature", "dep:sm3"]
4848
getrandom = ["elliptic-curve/getrandom"]
49-
pke = ["arithmetic", "dep:sm3"]
49+
pke = ["arithmetic", "dep:sm3", "pkcs8", "alloc"]
5050
pem = ["elliptic-curve/pem", "pkcs8"]
5151
pkcs8 = ["elliptic-curve/pkcs8", "der"]
5252
serde = ["elliptic-curve/serde", "primeorder?/serde", "serdect"]

sm2/src/dsa.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ use alloc::vec::Vec;
6060

6161
#[cfg(feature = "pkcs8")]
6262
use crate::pkcs8::{
63-
AlgorithmIdentifierRef, ObjectIdentifier,
64-
der::{self as der_core, AnyRef, asn1::BitString},
65-
spki::AssociatedAlgorithmIdentifier,
63+
AlgorithmIdentifierRef, ObjectIdentifier, der::AnyRef, spki::AssociatedAlgorithmIdentifier,
6664
};
6765

6866
#[cfg(all(feature = "alloc", feature = "pkcs8"))]
69-
use crate::pkcs8::spki::SignatureBitStringEncoding;
67+
use crate::pkcs8::{
68+
der::{self as der_core, asn1::BitString},
69+
spki::SignatureBitStringEncoding,
70+
};
7071

7172
/// SM2DSA signature size.
7273
pub type SignatureSize = <FieldBytesSize as Add>::Output;
@@ -238,7 +239,7 @@ impl SignatureBitStringEncoding for Signature {
238239
}
239240
}
240241

241-
#[cfg(all(feature = "alloc", feature = "pkcs8"))]
242+
#[cfg(feature = "pkcs8")]
242243
impl AssociatedAlgorithmIdentifier for Signature {
243244
type Params = AnyRef<'static>;
244245

sm2/src/pke/encrypting.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::{
66
pke::{kdf, vec},
77
};
88

9-
#[cfg(feature = "alloc")]
109
use alloc::{borrow::ToOwned, boxed::Box, vec::Vec};
1110
use elliptic_curve::{
1211
Error, Generate, Group, Result,
@@ -68,7 +67,6 @@ impl EncryptingKey {
6867
/// (page 10).
6968
///
7069
/// <http://www.secg.org/sec1-v2.pdf>
71-
#[cfg(feature = "alloc")]
7270
pub fn to_sec1_bytes(&self) -> Box<[u8]> {
7371
self.public_key.to_sec1_bytes()
7472
}

0 commit comments

Comments
 (0)