Skip to content

Commit db39e4d

Browse files
authored
Better gating of alloc (#62)
Gate all `alloc` usage with feature `alloc` instead of not std. Update CI to check `alloc` feature only build & test. Resolves #36.
1 parent 9802e4a commit db39e4d

File tree

13 files changed

+31
-28
lines changed

13 files changed

+31
-28
lines changed

.github/workflows/rustls-rustcrypto.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
with:
3131
toolchain: ${{ matrix.toolchain }}
3232
- run: cargo build
33+
- name: Test no_std with alloc build
34+
run: cargo build --no-default-features --features tls12,alloc
3335

3436
clippy:
3537
runs-on: ubuntu-latest
@@ -74,3 +76,5 @@ jobs:
7476
with:
7577
toolchain: ${{ matrix.toolchain }}
7678
- run: cargo test --features tls12
79+
- name: Test no_std with alloc
80+
run: cargo test --no-default-features --features tls12,alloc

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
WIP RustCrypto-based provider implementation for version 0.23 of [rustls](https://github.com/rustls/rustls/pull/1405).
44

5-
Some code comes directly from one of main rustls contributor, [@ctz](https://github.com/ctz).
5+
Some code comes directly from one of main rustls contributor, [@ctz](https://github.com/ctz).
66

77
Some part of this code is directly derived from his work but modified to use generic instead.
88

99
## ⚠️USE THIS AT YOUR OWN RISK! DO NOT USE THIS IN PRODUCTION⚠️
1010

11-
Not only that this is incomplete that only few selected TLS suites implemented (it should be well enough to cover 70% of the usage), but the elephant in the room is that neither did rustls nor RustCrypto packages were formally verified and certified with FIPS compliance.
11+
Not only that this is incomplete that only few selected TLS suites implemented (it should be well enough to cover 70% of the usage), but the elephant in the room is that neither did rustls nor RustCrypto packages were formally verified and certified with FIPS compliance.
1212

1313
Note that RustCrypto performance is generally inferior than ring, but in exchange you got a pure Rust implementation that theoretically compiles everywhere Rust was ported to. In our case, we need to have `std` but foundational support for future `no_std` expansion is already here.
1414

15-
This package is still in its very early phase, so until we think the code is okay for general public use, this won't be published to crates.io anytime soon.
15+
This package is still in its very early phase, so until we think the code is okay for general public use, this won't be published to crates.io anytime soon.
1616

1717
Meanwhile you can try it out using git crate installation:
18-
```
18+
19+
```toml
1920
rustls-rustcrypto = { git = "https://github.com/RustCrypto/rustls-rustcrypto", version = "0.1" }
2021
```
2122

@@ -33,14 +34,14 @@ rustls-rustcrypto = { git = "https://github.com/RustCrypto/rustls-rustcrypto", v
3334

3435
## QUIC Support
3536

36-
There won't be QUIC support anytime soon until https://github.com/rustls/rustls/issues/1491 is solved. HTTP/2 however should work out of the box.
37+
There won't be QUIC support anytime soon until <https://github.com/rustls/rustls/issues/1491> is solved. HTTP/2 however should work out of the box.
3738

3839
## License
3940

4041
Licensed under either of:
4142

42-
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
43-
* [MIT license](http://opensource.org/licenses/MIT)
43+
- [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
44+
- [MIT license](http://opensource.org/licenses/MIT)
4445

4546
at your option.
4647

src/aead/chacha20.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(not(feature = "std"))]
1+
#[cfg(feature = "alloc")]
22
use alloc::boxed::Box;
33

44
use super::{DecryptBufferAdapter, EncryptBufferAdapter};

src/aead/gcm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(not(feature = "std"))]
1+
#[cfg(feature = "alloc")]
22
use alloc::boxed::Box;
33

44
use super::{DecryptBufferAdapter, EncryptBufferAdapter};

src/hash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(not(feature = "std"))]
1+
#[cfg(feature = "alloc")]
22
use alloc::boxed::Box;
33

44
use digest::{Digest, OutputSizeUser};

src/hmac.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(not(feature = "std"))]
1+
#[cfg(feature = "alloc")]
22
use alloc::boxed::Box;
33

44
use crypto_common::OutputSizeUser;

src/kx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(not(feature = "std"))]
1+
#[cfg(feature = "alloc")]
22
use alloc::boxed::Box;
33

44
use crypto::{SharedSecret, SupportedKxGroup};

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
)]
88
#![cfg_attr(not(feature = "std"), no_std)]
99

10+
#[cfg(not(feature = "alloc"))]
11+
compile_error!("Rustls currently does not support alloc-less environments");
12+
13+
#[cfg(feature = "alloc")]
1014
extern crate alloc;
1115

16+
#[cfg(feature = "alloc")]
1217
use alloc::sync::Arc;
1318

1419
use rustls::crypto::{

src/quic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(clippy::duplicate_mod)]
22

3-
#[cfg(not(feature = "std"))]
3+
#[cfg(feature = "alloc")]
44
use alloc::boxed::Box;
55

66
use aead::AeadCore;

src/sign.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use alloc::sync::Arc;
2-
#[cfg(not(feature = "std"))]
3-
use alloc::vec::Vec;
1+
#[cfg(feature = "alloc")]
2+
use alloc::{sync::Arc, vec::Vec};
43
use core::marker::PhantomData;
54

65
use self::ecdsa::{EcdsaSigningKeyP256, EcdsaSigningKeyP384};

0 commit comments

Comments
 (0)