Skip to content

Commit 0c88590

Browse files
authored
Switch pub static values to pub const (#905)
* Switch digest::Algorithms from static to const * Change more static to const
1 parent b161316 commit 0c88590

File tree

9 files changed

+105
-106
lines changed

9 files changed

+105
-106
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ jobs:
160160
strategy:
161161
matrix:
162162
args:
163-
-
163+
- ''
164164
- --release
165165
features:
166166
- --features asan

aws-lc-rs/src/aead/quic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,21 @@ impl PartialEq for Algorithm {
120120
impl Eq for Algorithm {}
121121

122122
/// AES-128.
123-
pub static AES_128: Algorithm = Algorithm {
123+
pub const AES_128: Algorithm = Algorithm {
124124
key_len: 16,
125125
init: SymmetricCipherKey::aes128,
126126
id: AlgorithmID::AES_128,
127127
};
128128

129129
/// AES-256.
130-
pub static AES_256: Algorithm = Algorithm {
130+
pub const AES_256: Algorithm = Algorithm {
131131
key_len: 32,
132132
init: SymmetricCipherKey::aes256,
133133
id: AlgorithmID::AES_256,
134134
};
135135

136136
/// `ChaCha20`.
137-
pub static CHACHA20: Algorithm = Algorithm {
137+
pub const CHACHA20: Algorithm = Algorithm {
138138
key_len: 32,
139139
init: SymmetricCipherKey::chacha20,
140140
id: AlgorithmID::CHACHA20,

aws-lc-rs/src/cipher.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,21 +374,21 @@ pub struct Algorithm {
374374
}
375375

376376
/// AES 128-bit cipher
377-
pub static AES_128: Algorithm = Algorithm {
377+
pub const AES_128: Algorithm = Algorithm {
378378
id: AlgorithmId::Aes128,
379379
key_len: AES_128_KEY_LEN,
380380
block_len: AES_BLOCK_LEN,
381381
};
382382

383383
/// AES 192-bit cipher
384-
pub static AES_192: Algorithm = Algorithm {
384+
pub const AES_192: Algorithm = Algorithm {
385385
id: AlgorithmId::Aes192,
386386
key_len: AES_192_KEY_LEN,
387387
block_len: AES_BLOCK_LEN,
388388
};
389389

390390
/// AES 256-bit cipher
391-
pub static AES_256: Algorithm = Algorithm {
391+
pub const AES_256: Algorithm = Algorithm {
392392
id: AlgorithmId::Aes256,
393393
key_len: AES_256_KEY_LEN,
394394
block_len: AES_BLOCK_LEN,

aws-lc-rs/src/digest/sha.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const DIGEST_MAX_INPUT_LEN: u64 = u64::MAX;
6060
///
6161
/// [FIPS 180-4]: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
6262
#[allow(deprecated)]
63-
pub static SHA1_FOR_LEGACY_USE_ONLY: Algorithm = Algorithm {
63+
pub const SHA1_FOR_LEGACY_USE_ONLY: Algorithm = Algorithm {
6464
output_len: SHA1_OUTPUT_LEN,
6565
chaining_len: SHA1_OUTPUT_LEN,
6666
block_len: SHA1_BLOCK_LEN,
@@ -75,7 +75,7 @@ pub static SHA1_FOR_LEGACY_USE_ONLY: Algorithm = Algorithm {
7575
///
7676
/// [FIPS 180-4]: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
7777
#[allow(deprecated)]
78-
pub static SHA224: Algorithm = Algorithm {
78+
pub const SHA224: Algorithm = Algorithm {
7979
output_len: SHA224_OUTPUT_LEN,
8080

8181
// The chaining length is equivalent to the length before truncation.
@@ -93,7 +93,7 @@ pub static SHA224: Algorithm = Algorithm {
9393
///
9494
/// [FIPS 180-4]: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
9595
#[allow(deprecated)]
96-
pub static SHA256: Algorithm = Algorithm {
96+
pub const SHA256: Algorithm = Algorithm {
9797
output_len: SHA256_OUTPUT_LEN,
9898
chaining_len: SHA256_OUTPUT_LEN,
9999
block_len: SHA256_BLOCK_LEN,
@@ -108,7 +108,7 @@ pub static SHA256: Algorithm = Algorithm {
108108
///
109109
/// [FIPS 180-4]: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
110110
#[allow(deprecated)]
111-
pub static SHA384: Algorithm = Algorithm {
111+
pub const SHA384: Algorithm = Algorithm {
112112
output_len: SHA384_OUTPUT_LEN,
113113

114114
// The chaining length is equivalent to the length before truncation.
@@ -126,7 +126,7 @@ pub static SHA384: Algorithm = Algorithm {
126126
///
127127
/// [FIPS 180-4]: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
128128
#[allow(deprecated)]
129-
pub static SHA512: Algorithm = Algorithm {
129+
pub const SHA512: Algorithm = Algorithm {
130130
output_len: SHA512_OUTPUT_LEN,
131131
chaining_len: SHA512_OUTPUT_LEN,
132132
block_len: SHA512_BLOCK_LEN,
@@ -141,7 +141,7 @@ pub static SHA512: Algorithm = Algorithm {
141141
///
142142
/// [FIPS 180-4]: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
143143
#[allow(deprecated)]
144-
pub static SHA512_256: Algorithm = Algorithm {
144+
pub const SHA512_256: Algorithm = Algorithm {
145145
output_len: SHA512_256_OUTPUT_LEN,
146146
chaining_len: SHA512_OUTPUT_LEN,
147147
block_len: SHA512_BLOCK_LEN,
@@ -156,7 +156,7 @@ pub static SHA512_256: Algorithm = Algorithm {
156156
///
157157
/// [FIPS 202]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf
158158
#[allow(deprecated)]
159-
pub static SHA3_256: Algorithm = Algorithm {
159+
pub const SHA3_256: Algorithm = Algorithm {
160160
output_len: SHA3_256_OUTPUT_LEN,
161161
chaining_len: SHA3_256_OUTPUT_LEN,
162162
block_len: SHA3_256_BLOCK_LEN,
@@ -171,7 +171,7 @@ pub static SHA3_256: Algorithm = Algorithm {
171171
///
172172
/// [FIPS 202]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf
173173
#[allow(deprecated)]
174-
pub static SHA3_384: Algorithm = Algorithm {
174+
pub const SHA3_384: Algorithm = Algorithm {
175175
output_len: SHA3_384_OUTPUT_LEN,
176176
chaining_len: SHA3_384_OUTPUT_LEN,
177177
block_len: SHA3_384_BLOCK_LEN,
@@ -186,7 +186,7 @@ pub static SHA3_384: Algorithm = Algorithm {
186186
///
187187
/// [FIPS 202]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf
188188
#[allow(deprecated)]
189-
pub static SHA3_512: Algorithm = Algorithm {
189+
pub const SHA3_512: Algorithm = Algorithm {
190190
output_len: SHA3_512_OUTPUT_LEN,
191191
chaining_len: SHA3_512_OUTPUT_LEN,
192192
block_len: SHA3_512_BLOCK_LEN,

aws-lc-rs/src/hkdf.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,16 @@ impl Algorithm {
5959
}
6060

6161
/// HKDF using HMAC-SHA-1. Obsolete.
62-
pub static HKDF_SHA1_FOR_LEGACY_USE_ONLY: Algorithm =
63-
Algorithm(hmac::HMAC_SHA1_FOR_LEGACY_USE_ONLY);
62+
pub const HKDF_SHA1_FOR_LEGACY_USE_ONLY: Algorithm = Algorithm(hmac::HMAC_SHA1_FOR_LEGACY_USE_ONLY);
6463

6564
/// HKDF using HMAC-SHA-256.
66-
pub static HKDF_SHA256: Algorithm = Algorithm(hmac::HMAC_SHA256);
65+
pub const HKDF_SHA256: Algorithm = Algorithm(hmac::HMAC_SHA256);
6766

6867
/// HKDF using HMAC-SHA-384.
69-
pub static HKDF_SHA384: Algorithm = Algorithm(hmac::HMAC_SHA384);
68+
pub const HKDF_SHA384: Algorithm = Algorithm(hmac::HMAC_SHA384);
7069

7170
/// HKDF using HMAC-SHA-512.
72-
pub static HKDF_SHA512: Algorithm = Algorithm(hmac::HMAC_SHA512);
71+
pub const HKDF_SHA512: Algorithm = Algorithm(hmac::HMAC_SHA512);
7372

7473
/// General Salt length's for HKDF don't normally exceed 256 bits.
7574
/// We set the limit to something tolerable, so that the Salt structure can be stack allocatable.

aws-lc-rs/src/hmac.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,19 @@ impl Algorithm {
133133
}
134134

135135
/// HMAC using SHA-1. Obsolete.
136-
pub static HMAC_SHA1_FOR_LEGACY_USE_ONLY: Algorithm = Algorithm(&digest::SHA1_FOR_LEGACY_USE_ONLY);
136+
pub const HMAC_SHA1_FOR_LEGACY_USE_ONLY: Algorithm = Algorithm(&digest::SHA1_FOR_LEGACY_USE_ONLY);
137137

138138
/// HMAC using SHA-224.
139-
pub static HMAC_SHA224: Algorithm = Algorithm(&digest::SHA224);
139+
pub const HMAC_SHA224: Algorithm = Algorithm(&digest::SHA224);
140140

141141
/// HMAC using SHA-256.
142-
pub static HMAC_SHA256: Algorithm = Algorithm(&digest::SHA256);
142+
pub const HMAC_SHA256: Algorithm = Algorithm(&digest::SHA256);
143143

144144
/// HMAC using SHA-384.
145-
pub static HMAC_SHA384: Algorithm = Algorithm(&digest::SHA384);
145+
pub const HMAC_SHA384: Algorithm = Algorithm(&digest::SHA384);
146146

147147
/// HMAC using SHA-512.
148-
pub static HMAC_SHA512: Algorithm = Algorithm(&digest::SHA512);
148+
pub const HMAC_SHA512: Algorithm = Algorithm(&digest::SHA512);
149149

150150
/// An HMAC tag.
151151
///

aws-lc-rs/src/pbkdf2.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,25 @@ pub struct Algorithm {
120120
}
121121

122122
/// PBKDF2 using HMAC-SHA1.
123-
pub static PBKDF2_HMAC_SHA1: Algorithm = Algorithm {
123+
pub const PBKDF2_HMAC_SHA1: Algorithm = Algorithm {
124124
algorithm: hmac::HMAC_SHA1_FOR_LEGACY_USE_ONLY,
125125
max_output_len: MAX_USIZE32 * digest::SHA1_OUTPUT_LEN as u64,
126126
};
127127

128128
/// PBKDF2 using HMAC-SHA256.
129-
pub static PBKDF2_HMAC_SHA256: Algorithm = Algorithm {
129+
pub const PBKDF2_HMAC_SHA256: Algorithm = Algorithm {
130130
algorithm: hmac::HMAC_SHA256,
131131
max_output_len: MAX_USIZE32 * digest::SHA256_OUTPUT_LEN as u64,
132132
};
133133

134134
/// PBKDF2 using HMAC-SHA384.
135-
pub static PBKDF2_HMAC_SHA384: Algorithm = Algorithm {
135+
pub const PBKDF2_HMAC_SHA384: Algorithm = Algorithm {
136136
algorithm: hmac::HMAC_SHA384,
137137
max_output_len: MAX_USIZE32 * digest::SHA384_OUTPUT_LEN as u64,
138138
};
139139

140140
/// PBKDF2 using HMAC-SHA512.
141-
pub static PBKDF2_HMAC_SHA512: Algorithm = Algorithm {
141+
pub const PBKDF2_HMAC_SHA512: Algorithm = Algorithm {
142142
algorithm: hmac::HMAC_SHA512,
143143
max_output_len: MAX_USIZE32 * digest::SHA512_OUTPUT_LEN as u64,
144144
};

0 commit comments

Comments
 (0)