Skip to content

Commit 6b2c76d

Browse files
[utils] Introduce Span (and rename array to sequence) (#1337)
1 parent 525cac4 commit 6b2c76d

46 files changed

Lines changed: 106 additions & 68 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

consensus/src/marshal/actor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use commonware_storage::{
2525
archive::{self, immutable, prunable, Archive as _, Identifier},
2626
translator::TwoCap,
2727
};
28-
use commonware_utils::{array::U64, Array};
28+
use commonware_utils::{sequence::U64, Array};
2929
use futures::{
3030
channel::{mpsc, oneshot},
3131
try_join, StreamExt,

consensus/src/marshal/finalizer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{marshal::ingress::orchestrator::Orchestrator, Block, Reporter};
22
use commonware_runtime::{Clock, Metrics, Spawner, Storage};
33
use commonware_storage::metadata::{self, Metadata};
4-
use commonware_utils::array::FixedBytes;
4+
use commonware_utils::sequence::FixedBytes;
55
use futures::{channel::mpsc, StreamExt};
66
use tracing::{debug, error};
77

cryptography/src/blake3/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::Hasher;
2424
use blake3::Hash;
2525
use bytes::{Buf, BufMut};
2626
use commonware_codec::{Error as CodecError, FixedSize, Read, ReadExt, Write};
27-
use commonware_utils::{hex, Array};
27+
use commonware_utils::{hex, Array, Span};
2828
use rand::{CryptoRng, Rng};
2929
use std::{
3030
fmt::{Debug, Display},
@@ -128,6 +128,8 @@ impl FixedSize for Digest {
128128
const SIZE: usize = DIGEST_LENGTH;
129129
}
130130

131+
impl Span for Digest {}
132+
131133
impl Array for Digest {}
132134

133135
impl From<Hash> for Digest {

cryptography/src/bls12381/scheme.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use bytes::{Buf, BufMut};
3434
use commonware_codec::{
3535
DecodeExt, EncodeFixed, Error as CodecError, FixedSize, Read, ReadExt, Write,
3636
};
37-
use commonware_utils::{hex, union_unique};
37+
use commonware_utils::{hex, union_unique, Span};
3838
use rand::{CryptoRng, Rng};
3939
use std::{
4040
borrow::Cow,
@@ -74,6 +74,8 @@ impl FixedSize for PrivateKey {
7474
const SIZE: usize = group::PRIVATE_KEY_LENGTH;
7575
}
7676

77+
impl Span for PrivateKey {}
78+
7779
impl Array for PrivateKey {}
7880

7981
impl Hash for PrivateKey {
@@ -200,6 +202,8 @@ impl FixedSize for PublicKey {
200202
const SIZE: usize = <MinPk as Variant>::Public::SIZE;
201203
}
202204

205+
impl Span for PublicKey {}
206+
203207
impl Array for PublicKey {}
204208

205209
impl Hash for PublicKey {
@@ -288,6 +292,8 @@ impl FixedSize for Signature {
288292
const SIZE: usize = <MinPk as Variant>::Signature::SIZE;
289293
}
290294

295+
impl Span for Signature {}
296+
291297
impl Array for Signature {}
292298

293299
impl Hash for Signature {

cryptography/src/bls12381/tle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ use crate::{
8989
};
9090
use bytes::{Buf, BufMut};
9191
use commonware_codec::{EncodeSize, FixedSize, Read, ReadExt, Write};
92-
use commonware_utils::array::FixedBytes;
92+
use commonware_utils::sequence::FixedBytes;
9393
use rand::{CryptoRng, Rng};
9494

9595
/// Domain separation tag for hashing the `h3` message to a scalar.

cryptography/src/ed25519/scheme.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{Array, BatchVerifier, PrivateKeyExt};
22
use bytes::{Buf, BufMut};
33
use commonware_codec::{Error as CodecError, FixedSize, Read, ReadExt, Write};
4-
use commonware_utils::{hex, union_unique};
4+
use commonware_utils::{hex, union_unique, Span};
55
use ed25519_consensus::{self, VerificationKey};
66
use rand::{CryptoRng, Rng, RngCore};
77
use std::{
@@ -75,6 +75,8 @@ impl FixedSize for PrivateKey {
7575
const SIZE: usize = PRIVATE_KEY_LENGTH;
7676
}
7777

78+
impl Span for PrivateKey {}
79+
7880
impl Array for PrivateKey {}
7981

8082
impl Eq for PrivateKey {}
@@ -189,6 +191,8 @@ impl FixedSize for PublicKey {
189191
const SIZE: usize = PUBLIC_KEY_LENGTH;
190192
}
191193

194+
impl Span for PublicKey {}
195+
192196
impl Array for PublicKey {}
193197

194198
impl AsRef<[u8]> for PublicKey {
@@ -252,6 +256,8 @@ impl FixedSize for Signature {
252256
const SIZE: usize = SIGNATURE_LENGTH;
253257
}
254258

259+
impl Span for Signature {}
260+
255261
impl Array for Signature {}
256262

257263
impl Hash for Signature {

cryptography/src/secp256r1/scheme.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{Array, PrivateKeyExt};
22
use bytes::{Buf, BufMut};
33
use commonware_codec::{Error as CodecError, FixedSize, Read, ReadExt, Write};
4-
use commonware_utils::{hex, union_unique};
4+
use commonware_utils::{hex, union_unique, Span};
55
use p256::{
66
ecdsa::{
77
signature::{Signer, Verifier},
@@ -91,6 +91,8 @@ impl FixedSize for PrivateKey {
9191
const SIZE: usize = PRIVATE_KEY_LENGTH;
9292
}
9393

94+
impl Span for PrivateKey {}
95+
9496
impl Array for PrivateKey {}
9597

9698
impl Hash for PrivateKey {
@@ -196,6 +198,8 @@ impl FixedSize for PublicKey {
196198
const SIZE: usize = PUBLIC_KEY_LENGTH;
197199
}
198200

201+
impl Span for PublicKey {}
202+
199203
impl Array for PublicKey {}
200204

201205
impl Hash for PublicKey {
@@ -271,6 +275,8 @@ impl FixedSize for Signature {
271275
const SIZE: usize = SIGNATURE_LENGTH;
272276
}
273277

278+
impl Span for Signature {}
279+
274280
impl Array for Signature {}
275281

276282
impl Hash for Signature {

cryptography/src/sha256/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use crate::Hasher;
2424
use bytes::{Buf, BufMut};
2525
use commonware_codec::{DecodeExt, Error as CodecError, FixedSize, Read, ReadExt, Write};
26-
use commonware_utils::{hex, Array};
26+
use commonware_utils::{hex, Array, Span};
2727
use rand::{CryptoRng, Rng};
2828
use sha2::{Digest as _, Sha256 as ISha256};
2929
use std::{
@@ -122,6 +122,8 @@ impl FixedSize for Digest {
122122
const SIZE: usize = DIGEST_LENGTH;
123123
}
124124

125+
impl Span for Digest {}
126+
125127
impl Array for Digest {}
126128

127129
impl From<[u8; DIGEST_LENGTH]> for Digest {

resolver/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//! Resolve data identified by a fixed-length key.
22
3-
use commonware_utils::Array;
3+
use commonware_utils::Span;
44
use std::future::Future;
55

66
pub mod p2p;
77

88
/// Notified when data is available, and must validate it.
99
pub trait Consumer: Clone + Send + 'static {
1010
/// Type used to uniquely identify data.
11-
type Key: Array;
11+
type Key: Span;
1212

1313
/// Type of data to retrieve.
1414
type Value;
@@ -31,7 +31,7 @@ pub trait Consumer: Clone + Send + 'static {
3131
/// Responsible for fetching data and notifying a `Consumer`.
3232
pub trait Resolver: Clone + Send + 'static {
3333
/// Type used to uniquely identify data.
34-
type Key: Array;
34+
type Key: Span;
3535

3636
/// Initiate a fetch request.
3737
fn fetch(&mut self, key: Self::Key) -> impl Future<Output = ()> + Send;

resolver/src/p2p/mocks/consumer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::Array;
1+
use crate::Span;
22
use futures::{channel::mpsc, SinkExt};
33
use std::collections::HashMap;
44

@@ -14,7 +14,7 @@ pub enum Event<K, V> {
1414

1515
/// A consumer that can be used for testing
1616
#[derive(Clone)]
17-
pub struct Consumer<K: Array, V> {
17+
pub struct Consumer<K: Span, V> {
1818
/// The sender to send events to
1919
sender: mpsc::UnboundedSender<Event<K, V>>,
2020

@@ -24,7 +24,7 @@ pub struct Consumer<K: Array, V> {
2424
expected: HashMap<K, V>,
2525
}
2626

27-
impl<K: Array, V: Clone + PartialEq> Consumer<K, V> {
27+
impl<K: Span, V: Clone + PartialEq> Consumer<K, V> {
2828
/// Create a new consumer
2929
///
3030
/// Returns the consumer and a receiver that can be used to get the events
@@ -59,7 +59,7 @@ impl<K: Array, V: Clone + PartialEq> Consumer<K, V> {
5959
}
6060
}
6161

62-
impl<K: Array, V: Clone + PartialEq + Send + 'static> crate::Consumer for Consumer<K, V> {
62+
impl<K: Span, V: Clone + PartialEq + Send + 'static> crate::Consumer for Consumer<K, V> {
6363
type Key = K;
6464
type Value = V;
6565
type Failure = ();

0 commit comments

Comments
 (0)