From 9d6348893f2aa194974d294bf22c3cb00f16455a Mon Sep 17 00:00:00 2001 From: Dmitry Markin Date: Tue, 16 Apr 2024 17:26:20 +0300 Subject: [PATCH 1/4] Re-export `multihash` & `multiaddr` types --- src/types.rs | 2 ++ src/types/multiaddr.rs | 22 ++++++++++++++++++++++ src/types/multihash.rs | 22 ++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 src/types/multiaddr.rs create mode 100644 src/types/multihash.rs diff --git a/src/types.rs b/src/types.rs index 5b1251294..741efe81f 100644 --- a/src/types.rs +++ b/src/types.rs @@ -22,6 +22,8 @@ use rand::Rng; +pub mod multiaddr; +pub mod multihash; pub mod protocol; /// Substream ID. diff --git a/src/types/multiaddr.rs b/src/types/multiaddr.rs new file mode 100644 index 000000000..7046367b2 --- /dev/null +++ b/src/types/multiaddr.rs @@ -0,0 +1,22 @@ +// Copyright 2023 litep2p developers +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +// Re-export the types used in public interfaces. +pub use multiaddr::{Error, Multiaddr, Onion3Addr, Protocol, Iter}; diff --git a/src/types/multihash.rs b/src/types/multihash.rs new file mode 100644 index 000000000..a455c3fdd --- /dev/null +++ b/src/types/multihash.rs @@ -0,0 +1,22 @@ +// Copyright 2023 litep2p developers +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +// Re-export the types used in public interfaces. +pub use multihash::{Code, Error, Multihash, MultihashDigest}; From 059e12cc2e4b755a2bbfb7babb6b652896bbc037 Mon Sep 17 00:00:00 2001 From: Dmitry Markin Date: Thu, 18 Apr 2024 18:04:55 +0300 Subject: [PATCH 2/4] minor: rustfmt --- src/types/multiaddr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/multiaddr.rs b/src/types/multiaddr.rs index 7046367b2..5f454fcb8 100644 --- a/src/types/multiaddr.rs +++ b/src/types/multiaddr.rs @@ -19,4 +19,4 @@ // DEALINGS IN THE SOFTWARE. // Re-export the types used in public interfaces. -pub use multiaddr::{Error, Multiaddr, Onion3Addr, Protocol, Iter}; +pub use multiaddr::{Error, Iter, Multiaddr, Onion3Addr, Protocol}; From 8f11c14d53d838510d5011a9c22266e336ef15f9 Mon Sep 17 00:00:00 2001 From: Dmitry Markin Date: Tue, 23 Apr 2024 17:26:51 +0300 Subject: [PATCH 3/4] Expose `to_bytes()` for Ed25519 `SecretKey` --- src/crypto/ed25519.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/crypto/ed25519.rs b/src/crypto/ed25519.rs index 852d4e0f1..2d43ebf11 100644 --- a/src/crypto/ed25519.rs +++ b/src/crypto/ed25519.rs @@ -202,6 +202,11 @@ impl SecretKey { sk_bytes.zeroize(); Ok(SecretKey(secret)) } + + /// Convert this secret key to a byte array. + pub fn to_bytes(&self) -> [u8; 32] { + self.0.to_bytes() + } } #[cfg(test)] From 4538a25f1f6a4b8e1ebbc1c06c49ea756cb45311 Mon Sep 17 00:00:00 2001 From: Dmitry Markin Date: Tue, 23 Apr 2024 19:09:20 +0300 Subject: [PATCH 4/4] Use inline module declarations for re-exports --- src/types.rs | 10 ++++++++-- src/types/multiaddr.rs | 22 ---------------------- src/types/multihash.rs | 22 ---------------------- 3 files changed, 8 insertions(+), 46 deletions(-) delete mode 100644 src/types/multiaddr.rs delete mode 100644 src/types/multihash.rs diff --git a/src/types.rs b/src/types.rs index 741efe81f..8f40b78bc 100644 --- a/src/types.rs +++ b/src/types.rs @@ -22,8 +22,14 @@ use rand::Rng; -pub mod multiaddr; -pub mod multihash; +// Re-export the types used in public interfaces. +pub mod multiaddr { + pub use multiaddr::{Error, Iter, Multiaddr, Onion3Addr, Protocol}; +} +pub mod multihash { + pub use multihash::{Code, Error, Multihash, MultihashDigest}; +} + pub mod protocol; /// Substream ID. diff --git a/src/types/multiaddr.rs b/src/types/multiaddr.rs deleted file mode 100644 index 5f454fcb8..000000000 --- a/src/types/multiaddr.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2023 litep2p developers -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// Re-export the types used in public interfaces. -pub use multiaddr::{Error, Iter, Multiaddr, Onion3Addr, Protocol}; diff --git a/src/types/multihash.rs b/src/types/multihash.rs deleted file mode 100644 index a455c3fdd..000000000 --- a/src/types/multihash.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2023 litep2p developers -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// Re-export the types used in public interfaces. -pub use multihash::{Code, Error, Multihash, MultihashDigest};