Skip to content

Commit 1ce212a

Browse files
committed
rework feature set
This allows to bring the rustcrypto "base" and then limit the support to only the type of keys or hash you need Signed-off-by: Arthur Gautier <[email protected]>
1 parent 697f280 commit 1ce212a

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

tss-esapi/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,7 @@ semver = "1.0.7"
7272
[features]
7373
default = ["abstraction"]
7474
generate-bindings = ["tss-esapi-sys/generate-bindings"]
75-
abstraction = ["ecdsa", "elliptic-curve", "signature", "rsa", "x509-cert", "p192", "p224", "p256", "p384", "p521", "sha1", "sha2", "sha3", "sm2", "sm3"]
75+
abstraction = ["rustcrypto"]
7676
integration-tests = ["strum", "strum_macros"]
77+
rustcrypto = ["ecdsa", "elliptic-curve", "signature", "x509-cert"]
78+
rustcrypto-full = ["rustcrypto", "p192", "p224", "p256", "p384", "p521", "rsa", "sha1", "sha2", "sha3", "sm2", "sm3"]

tss-esapi/src/abstraction/hashing.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,42 @@ pub trait AssociatedHashingAlgorithm {
99
const TPM_DIGEST: HashingAlgorithm;
1010
}
1111

12-
#[cfg(feature = "sha1")]
12+
#[cfg(all(feature = "rustcrypto", feature = "sha1"))]
1313
impl AssociatedHashingAlgorithm for sha1::Sha1 {
1414
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha1;
1515
}
1616

17-
#[cfg(feature = "sha2")]
17+
#[cfg(all(feature = "rustcrypto", feature = "sha2"))]
1818
impl AssociatedHashingAlgorithm for sha2::Sha256 {
1919
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha256;
2020
}
2121

22-
#[cfg(feature = "sha2")]
22+
#[cfg(all(feature = "rustcrypto", feature = "sha2"))]
2323
impl AssociatedHashingAlgorithm for sha2::Sha384 {
2424
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha384;
2525
}
2626

27-
#[cfg(feature = "sha2")]
27+
#[cfg(all(feature = "rustcrypto", feature = "sha2"))]
2828
impl AssociatedHashingAlgorithm for sha2::Sha512 {
2929
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha512;
3030
}
3131

32-
#[cfg(feature = "sm3")]
32+
#[cfg(all(feature = "rustcrypto", feature = "sm3"))]
3333
impl AssociatedHashingAlgorithm for sm3::Sm3 {
3434
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sm3_256;
3535
}
3636

37-
#[cfg(feature = "sha3")]
37+
#[cfg(all(feature = "rustcrypto", feature = "sha3"))]
3838
impl AssociatedHashingAlgorithm for sha3::Sha3_256 {
3939
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_256;
4040
}
4141

42-
#[cfg(feature = "sha3")]
42+
#[cfg(all(feature = "rustcrypto", feature = "sha3"))]
4343
impl AssociatedHashingAlgorithm for sha3::Sha3_384 {
4444
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_384;
4545
}
4646

47-
#[cfg(feature = "sha3")]
47+
#[cfg(all(feature = "rustcrypto", feature = "sha3"))]
4848
impl AssociatedHashingAlgorithm for sha3::Sha3_512 {
4949
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_512;
5050
}

tss-esapi/src/abstraction/public.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,17 @@ impl TryFrom<&Public> for SubjectPublicKeyInfoOwned {
127127
};
128128
}
129129

130-
#[cfg(feature = "p192")]
130+
#[cfg(all(feature = "rustcrypto", feature = "p192"))]
131131
read_key!(EccCurve::NistP192, p192::NistP192);
132-
#[cfg(feature = "p224")]
132+
#[cfg(all(feature = "rustcrypto", feature = "p224"))]
133133
read_key!(EccCurve::NistP224, p224::NistP224);
134-
#[cfg(feature = "p256")]
134+
#[cfg(all(feature = "rustcrypto", feature = "p256"))]
135135
read_key!(EccCurve::NistP256, p256::NistP256);
136-
#[cfg(feature = "p384")]
136+
#[cfg(all(feature = "rustcrypto", feature = "p384"))]
137137
read_key!(EccCurve::NistP384, p384::NistP384);
138-
#[cfg(feature = "p521")]
138+
#[cfg(all(feature = "rustcrypto", feature = "p521"))]
139139
read_key!(EccCurve::NistP521, p521::NistP521);
140-
#[cfg(feature = "sm2")]
140+
#[cfg(all(feature = "rustcrypto", feature = "sm2"))]
141141
read_key!(EccCurve::Sm2P256, sm2::Sm2);
142142

143143
Err(Error::local_error(WrapperErrorKind::UnsupportedParam))
@@ -207,32 +207,32 @@ pub trait AssociatedTpmCurve {
207207
const TPM_CURVE: EccCurve;
208208
}
209209

210-
#[cfg(feature = "p192")]
210+
#[cfg(all(feature = "rustcrypto", feature = "p192"))]
211211
impl AssociatedTpmCurve for p192::NistP192 {
212212
const TPM_CURVE: EccCurve = EccCurve::NistP192;
213213
}
214214

215-
#[cfg(feature = "p224")]
215+
#[cfg(all(feature = "rustcrypto", feature = "p224"))]
216216
impl AssociatedTpmCurve for p224::NistP224 {
217217
const TPM_CURVE: EccCurve = EccCurve::NistP224;
218218
}
219219

220-
#[cfg(feature = "p256")]
220+
#[cfg(all(feature = "rustcrypto", feature = "p256"))]
221221
impl AssociatedTpmCurve for p256::NistP256 {
222222
const TPM_CURVE: EccCurve = EccCurve::NistP256;
223223
}
224224

225-
#[cfg(feature = "p384")]
225+
#[cfg(all(feature = "rustcrypto", feature = "p384"))]
226226
impl AssociatedTpmCurve for p384::NistP384 {
227227
const TPM_CURVE: EccCurve = EccCurve::NistP384;
228228
}
229229

230-
#[cfg(feature = "p521")]
230+
#[cfg(all(feature = "rustcrypto", feature = "p521"))]
231231
impl AssociatedTpmCurve for p521::NistP521 {
232232
const TPM_CURVE: EccCurve = EccCurve::NistP521;
233233
}
234234

235-
#[cfg(feature = "sm2")]
235+
#[cfg(all(feature = "rustcrypto", feature = "sm2"))]
236236
impl AssociatedTpmCurve for sm2::Sm2 {
237237
const TPM_CURVE: EccCurve = EccCurve::Sm2P256;
238238
}

0 commit comments

Comments
 (0)