Skip to content

Commit

Permalink
Use derive_more crate's From/Into
Browse files Browse the repository at this point in the history
  • Loading branch information
akonradi-signal authored Jan 14, 2025
1 parent d1b37b0 commit 063db29
Show file tree
Hide file tree
Showing 35 changed files with 88 additions and 403 deletions.
35 changes: 31 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ criterion = "0.5"
ctr = "0.9.2"
curve25519-dalek = "4.1.3"
derive-where = "1.2.5"
derive_more = "1.0.0"
displaydoc = "0.2"
ed25519-dalek = "2.1.0"
env_logger = "0.11.4"
Expand Down
8 changes: 3 additions & 5 deletions acknowledgments/acknowledgments.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h1>Third Party Licenses</h1>

<h2>Overview of licenses:</h2>
<ul class="licenses-overview">
<li><a href="#MIT">MIT License</a> (343)</li>
<li><a href="#MIT">MIT License</a> (341)</li>
<li><a href="#AGPL-3.0">GNU Affero General Public License v3.0</a> (29)</li>
<li><a href="#Unicode-3.0">Unicode License v3</a> (19)</li>
<li><a href="#Apache-2.0">Apache License 2.0</a> (16)</li>
Expand Down Expand Up @@ -2839,15 +2839,11 @@ <h4>Used by:</h4>
<li><a href="https://github.com/microsoft/windows-rs">windows-sys 0.52.0</a></li>
<li><a href="https://github.com/microsoft/windows-rs">windows-sys 0.59.0</a></li>
<li><a href="https://github.com/microsoft/windows-rs">windows-targets 0.42.2</a></li>
<li><a href="https://github.com/microsoft/windows-rs">windows-targets 0.48.5</a></li>
<li><a href="https://github.com/microsoft/windows-rs">windows-targets 0.52.6</a></li>
<li><a href="https://github.com/microsoft/windows-rs">windows_aarch64_msvc 0.42.2</a></li>
<li><a href="https://github.com/microsoft/windows-rs">windows_aarch64_msvc 0.48.5</a></li>
<li><a href="https://github.com/microsoft/windows-rs">windows_aarch64_msvc 0.52.6</a></li>
<li><a href="https://github.com/microsoft/windows-rs">windows_x86_64_gnu 0.48.5</a></li>
<li><a href="https://github.com/microsoft/windows-rs">windows_x86_64_gnu 0.52.6</a></li>
<li><a href="https://github.com/microsoft/windows-rs">windows_x86_64_msvc 0.42.2</a></li>
<li><a href="https://github.com/microsoft/windows-rs">windows_x86_64_msvc 0.48.5</a></li>
<li><a href="https://github.com/microsoft/windows-rs">windows_x86_64_msvc 0.52.6</a></li>
</ul>
<pre class="license-text"> MIT License
Expand Down Expand Up @@ -8081,7 +8077,9 @@ <h4>Used by:</h4>
<h3 id="MIT">MIT License</h3>
<h4>Used by:</h4>
<ul class="license-used-by">
<li><a href="https://github.com/JelteF/derive_more">derive_more-impl 1.0.0</a></li>
<li><a href="https://github.com/JelteF/derive_more">derive_more 0.99.18</a></li>
<li><a href="https://github.com/JelteF/derive_more">derive_more 1.0.0</a></li>
</ul>
<pre class="license-text">The MIT License (MIT)

Expand Down
4 changes: 2 additions & 2 deletions acknowledgments/acknowledgments.md
Original file line number Diff line number Diff line change
Expand Up @@ -2685,7 +2685,7 @@ third-party/chromium/LICENSE.
```

## windows-core 0.52.0, windows-sys 0.45.0, windows-sys 0.52.0, windows-sys 0.59.0, windows-targets 0.42.2, windows-targets 0.48.5, windows-targets 0.52.6, windows_aarch64_msvc 0.42.2, windows_aarch64_msvc 0.48.5, windows_aarch64_msvc 0.52.6, windows_x86_64_gnu 0.48.5, windows_x86_64_gnu 0.52.6, windows_x86_64_msvc 0.42.2, windows_x86_64_msvc 0.48.5, windows_x86_64_msvc 0.52.6
## windows-core 0.52.0, windows-sys 0.45.0, windows-sys 0.52.0, windows-sys 0.59.0, windows-targets 0.42.2, windows-targets 0.52.6, windows_aarch64_msvc 0.42.2, windows_aarch64_msvc 0.52.6, windows_x86_64_gnu 0.52.6, windows_x86_64_msvc 0.42.2, windows_x86_64_msvc 0.52.6

```
MIT License
Expand Down Expand Up @@ -7442,7 +7442,7 @@ SOFTWARE.
```

## derive_more 0.99.18
## derive_more-impl 1.0.0, derive_more 0.99.18, derive_more 1.0.0

```
The MIT License (MIT)
Expand Down
4 changes: 2 additions & 2 deletions acknowledgments/acknowledgments.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2822,7 +2822,7 @@ third-party/chromium/LICENSE.
<key>License</key>
<string>MIT License</string>
<key>Title</key>
<string>windows-core 0.52.0, windows-sys 0.45.0, windows-sys 0.52.0, windows-sys 0.59.0, windows-targets 0.42.2, windows-targets 0.48.5, windows-targets 0.52.6, windows_aarch64_msvc 0.42.2, windows_aarch64_msvc 0.48.5, windows_aarch64_msvc 0.52.6, windows_x86_64_gnu 0.48.5, windows_x86_64_gnu 0.52.6, windows_x86_64_msvc 0.42.2, windows_x86_64_msvc 0.48.5, windows_x86_64_msvc 0.52.6</string>
<string>windows-core 0.52.0, windows-sys 0.45.0, windows-sys 0.52.0, windows-sys 0.59.0, windows-targets 0.42.2, windows-targets 0.52.6, windows_aarch64_msvc 0.42.2, windows_aarch64_msvc 0.52.6, windows_x86_64_gnu 0.52.6, windows_x86_64_msvc 0.42.2, windows_x86_64_msvc 0.52.6</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
Expand Down Expand Up @@ -8247,7 +8247,7 @@ SOFTWARE.
<key>License</key>
<string>MIT License</string>
<key>Title</key>
<string>derive_more 0.99.18</string>
<string>derive_more-impl 1.0.0, derive_more 0.99.18, derive_more 1.0.0</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
Expand Down
1 change: 1 addition & 0 deletions rust/account-keys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ workspace = true
libsignal-core = { workspace = true }

argon2 = { version = "0.5.0", features = ["zeroize"] }
derive_more = { workspace = true, features = ["from"] }
displaydoc = { workspace = true }
hkdf = { workspace = true }
partial-default = { workspace = true, features = ["derive"] }
Expand Down
14 changes: 1 addition & 13 deletions rust/account-keys/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

/// Error types for pin operations
#[derive(displaydoc::Display, thiserror::Error, Debug, Clone, Eq, PartialEq)]
#[derive(displaydoc::Display, thiserror::Error, Debug, Clone, Eq, PartialEq, derive_more::From)]
pub enum Error {
/// Argon2 hashing error: {0}
Argon2Error(argon2::Error),
Expand All @@ -14,16 +14,4 @@ pub enum Error {
MrenclaveLookupError,
}

impl From<argon2::Error> for Error {
fn from(e: argon2::Error) -> Self {
Error::Argon2Error(e)
}
}

impl From<argon2::password_hash::errors::Error> for Error {
fn from(e: argon2::password_hash::errors::Error) -> Self {
Error::DecodingError(e)
}
}

pub type Result<T> = std::result::Result<T, Error>;
1 change: 1 addition & 0 deletions rust/bridge/shared/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ aes-gcm-siv = { workspace = true }
async-trait = { workspace = true }
atomic-take = { workspace = true }
derive-where = { workspace = true }
derive_more = { workspace = true, features = ["from", "into"] }
displaydoc = { workspace = true }
futures-util = { workspace = true }
hmac = { workspace = true }
Expand Down
99 changes: 6 additions & 93 deletions rust/bridge/shared/types/src/jni/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::net::cdsi::CdsiError;
use crate::support::describe_panic;

/// The top-level error type for when something goes wrong.
#[derive(Debug, thiserror::Error)]
#[derive(Debug, thiserror::Error, derive_more::From)]
pub enum SignalJniError {
Protocol(SignalProtocolError),
DeviceTransfer(DeviceTransferError),
Expand All @@ -45,16 +45,19 @@ pub enum SignalJniError {
#[cfg(feature = "signal-media")]
WebpSanitizeParse(signal_media::sanitize::webp::ParseErrorReport),
Cdsi(CdsiError),
#[from(skip)]
Svr3(libsignal_net::svr3::Error),
WebSocket(#[from] WebSocketServiceError),
WebSocket(WebSocketServiceError),
ChatService(ChatServiceError),
InvalidUri(InvalidUri),
ConnectTimedOut,
BackupValidation(#[from] libsignal_message_backup::ReadError),
BackupValidation(libsignal_message_backup::ReadError),
Bridge(BridgeLayerError),
#[from(skip)]
TestingError {
exception_class: ClassName<'static>,
},
#[from(skip)]
KeyTransparency(libsignal_net::keytrans::Error),
}

Expand Down Expand Up @@ -143,90 +146,6 @@ impl fmt::Display for BridgeLayerError {
}
}

impl From<SignalProtocolError> for SignalJniError {
fn from(e: SignalProtocolError) -> SignalJniError {
SignalJniError::Protocol(e)
}
}

impl From<DeviceTransferError> for SignalJniError {
fn from(e: DeviceTransferError) -> SignalJniError {
SignalJniError::DeviceTransfer(e)
}
}

impl From<HsmEnclaveError> for SignalJniError {
fn from(e: HsmEnclaveError) -> SignalJniError {
SignalJniError::HsmEnclave(e)
}
}

impl From<EnclaveError> for SignalJniError {
fn from(e: EnclaveError) -> SignalJniError {
SignalJniError::Enclave(e)
}
}

impl From<PinError> for SignalJniError {
fn from(e: PinError) -> SignalJniError {
SignalJniError::Pin(e)
}
}

impl From<SignalCryptoError> for SignalJniError {
fn from(e: SignalCryptoError) -> SignalJniError {
SignalJniError::SignalCrypto(e)
}
}

impl From<ZkGroupVerificationFailure> for SignalJniError {
fn from(e: ZkGroupVerificationFailure) -> SignalJniError {
SignalJniError::ZkGroupVerificationFailure(e)
}
}

impl From<ZkGroupDeserializationFailure> for SignalJniError {
fn from(e: ZkGroupDeserializationFailure) -> SignalJniError {
SignalJniError::ZkGroupDeserializationFailure(e)
}
}

impl From<UsernameError> for SignalJniError {
fn from(e: UsernameError) -> Self {
SignalJniError::UsernameError(e)
}
}

impl From<usernames::ProofVerificationFailure> for SignalJniError {
fn from(e: usernames::ProofVerificationFailure) -> Self {
SignalJniError::UsernameProofError(e)
}
}

impl From<UsernameLinkError> for SignalJniError {
fn from(e: UsernameLinkError) -> Self {
SignalJniError::UsernameLinkError(e)
}
}

impl From<InvalidUri> for SignalJniError {
fn from(e: InvalidUri) -> Self {
SignalJniError::InvalidUri(e)
}
}

impl From<ChatServiceError> for SignalJniError {
fn from(e: ChatServiceError) -> Self {
SignalJniError::ChatService(e)
}
}

impl From<IoError> for SignalJniError {
fn from(e: IoError) -> SignalJniError {
Self::Io(e)
}
}

#[cfg(feature = "signal-media")]
impl From<signal_media::sanitize::mp4::Error> for SignalJniError {
fn from(e: signal_media::sanitize::mp4::Error) -> Self {
Expand Down Expand Up @@ -279,12 +198,6 @@ impl From<libsignal_net::cdsi::LookupError> for SignalJniError {
}
}

impl From<BridgeLayerError> for SignalJniError {
fn from(e: BridgeLayerError) -> SignalJniError {
SignalJniError::Bridge(e)
}
}

impl From<Svr3Error> for SignalJniError {
fn from(err: Svr3Error) -> Self {
match err {
Expand Down
Loading

0 comments on commit 063db29

Please sign in to comment.