Skip to content

Commit 1e7b09a

Browse files
Fix clippy warnings
1 parent c598333 commit 1e7b09a

File tree

7 files changed

+24
-28
lines changed

7 files changed

+24
-28
lines changed

core/src/mechanisms.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub trait Aes256Cbc: CryptoClient {
2929
wrapping_key,
3030
key,
3131
&[],
32-
iv.and_then(|iv| ShortData::try_from(iv).ok()),
32+
iv.map(ShortData::from),
3333
)
3434
}
3535
}
@@ -66,7 +66,7 @@ pub trait Chacha8Poly1305: CryptoClient {
6666
key,
6767
message,
6868
associated_data,
69-
nonce.and_then(|nonce| ShortData::try_from(nonce).ok()),
69+
nonce.map(ShortData::from),
7070
)
7171
}
7272

@@ -109,7 +109,7 @@ pub trait Chacha8Poly1305: CryptoClient {
109109
wrapping_key,
110110
key,
111111
associated_data,
112-
nonce.and_then(|nonce| ShortData::try_from(nonce).ok()),
112+
nonce.map(ShortData::from),
113113
)
114114
}
115115
}

src/mechanisms/chacha8poly1305.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ impl MechanismImpl for super::Chacha8Poly1305 {
152152
.try_into()
153153
.unwrap();
154154

155-
let nonce = ShortData::try_from(&nonce).unwrap();
156-
let tag = ShortData::try_from(&tag).unwrap();
155+
let nonce = ShortData::from(&nonce);
156+
let tag = ShortData::from(&tag);
157157

158158
// let ciphertext = Message::from_slice(&ciphertext).unwrap();
159159
Ok(reply::Encrypt {

src/mechanisms/ed255.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl MechanismImpl for super::Ed255 {
132132
let cose_pk = cosey::Ed25519PublicKey {
133133
// x: Bytes::from_slice(public_key.x_coordinate()).unwrap(),
134134
// x: Bytes::from_slice(&buf).unwrap(),
135-
x: Bytes::try_from(public_key.as_bytes()).unwrap(),
135+
x: Bytes::from(public_key.as_bytes()),
136136
};
137137
crate::cbor_serialize_bytes(&cose_pk).map_err(|_| Error::CborError)?
138138
}
@@ -187,7 +187,7 @@ impl MechanismImpl for super::Ed255 {
187187
let keypair = load_keypair(keystore, &key_id)?;
188188

189189
let native_signature = keypair.sign(&request.message);
190-
let our_signature = Signature::try_from(&native_signature.to_bytes()).unwrap();
190+
let our_signature = Signature::from(&native_signature.to_bytes());
191191

192192
// hprintln!("Ed255 signature:").ok();
193193
// hprintln!("msg: {:?}", &request.message).ok();

src/mechanisms/p256.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@ impl MechanismImpl for super::P256 {
205205
let serialized_key = match request.format {
206206
KeySerialization::EcdhEsHkdf256 => {
207207
let cose_pk = cosey::EcdhEsHkdf256PublicKey {
208-
x: Bytes::try_from(&public_key.x()).unwrap(),
209-
y: Bytes::try_from(&public_key.y()).unwrap(),
208+
x: Bytes::from(&public_key.x()),
209+
y: Bytes::from(&public_key.y()),
210210
};
211211
crate::cbor_serialize_bytes(&cose_pk).map_err(|_| Error::CborError)?
212212
}
213213
KeySerialization::Cose => {
214214
let cose_pk = cosey::P256PublicKey {
215-
x: Bytes::try_from(&public_key.x()).unwrap(),
216-
y: Bytes::try_from(&public_key.y()).unwrap(),
215+
x: Bytes::from(&public_key.x()),
216+
y: Bytes::from(&public_key.y()),
217217
};
218218
crate::cbor_serialize_bytes(&cose_pk).map_err(|_| Error::CborError)?
219219
}
@@ -269,9 +269,7 @@ impl MechanismImpl for super::P256 {
269269
let l = signature.to_sec1_bytes(&mut buffer);
270270
Signature::try_from(&buffer[..l]).unwrap()
271271
}
272-
SignatureSerialization::Raw => {
273-
Signature::try_from(&signature.to_untagged_bytes()).unwrap()
274-
}
272+
SignatureSerialization::Raw => Signature::from(&signature.to_untagged_bytes()),
275273
_ => {
276274
return Err(Error::InvalidSerializationFormat);
277275
}
@@ -354,9 +352,7 @@ impl MechanismImpl for super::P256Prehashed {
354352
let l = signature.to_sec1_bytes(&mut buffer);
355353
Signature::try_from(&buffer[..l]).unwrap()
356354
}
357-
SignatureSerialization::Raw => {
358-
Signature::try_from(&signature.to_untagged_bytes()).unwrap()
359-
}
355+
SignatureSerialization::Raw => Signature::from(&signature.to_untagged_bytes()),
360356
_ => {
361357
return Err(Error::InvalidSerializationFormat);
362358
}

src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ fn filesystem() {
951951
.metadata
952952
.is_none(),);
953953

954-
let data = Bytes::try_from(&[0; 20]).unwrap();
954+
let data = Bytes::from(&[0; 20]);
955955
block!(client
956956
.write_file(Location::Internal, path.clone(), data.clone(), None,)
957957
.expect("no client error"))

tests/filesystem.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ fn iterating(location: Location) {
6060
syscall!(client.write_file(
6161
location,
6262
PathBuf::from(path!("foo")),
63-
Bytes::try_from(b"foo").unwrap(),
63+
Bytes::from(b"foo"),
6464
None
6565
));
6666
syscall!(client.write_file(
6767
location,
6868
PathBuf::from(path!("bar")),
69-
Bytes::try_from(b"bar").unwrap(),
69+
Bytes::from(b"bar"),
7070
None
7171
));
7272
let first_entry = syscall!(client.read_dir_first(location, PathBuf::new(), None))

tests/serde_extensions.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ pub fn run<F: FnOnce(&mut Client<'_>)>(backends: &'static [BackendId<runner::id:
384384
fn test_extension() {
385385
use extensions::TestClient as _;
386386

387-
let msg = ShortData::try_from(&[0x01, 0x02, 0x03]).unwrap();
388-
let rev = ShortData::try_from(&[0x03, 0x02, 0x01]).unwrap();
387+
let msg = ShortData::from(&[0x01, 0x02, 0x03]);
388+
let rev = ShortData::from(&[0x03, 0x02, 0x01]);
389389
run(&[], |client| {
390390
assert!(trussed::try_syscall!(client.reverse(msg.clone())).is_err());
391391
});
@@ -409,9 +409,9 @@ fn sample_extension() {
409409
use extensions::SampleClient as _;
410410
use extensions::TestClient as _;
411411

412-
let msg = ShortData::try_from(&[1, 2, 3, 4]).unwrap();
413-
let rev = ShortData::try_from(&[4, 3, 2, 1]).unwrap();
414-
let trunc = ShortData::try_from(&[1, 2, 3]).unwrap();
412+
let msg = ShortData::from(&[1, 2, 3, 4]);
413+
let rev = ShortData::from(&[4, 3, 2, 1]);
414+
let trunc = ShortData::from(&[1, 2, 3]);
415415
run(&[], |client| {
416416
assert!(trussed::try_syscall!(client.truncate(msg.clone())).is_err());
417417
});
@@ -440,9 +440,9 @@ fn mixed_extension() {
440440
use extensions::SampleClient as _;
441441
use extensions::TestClient as _;
442442

443-
let msg = ShortData::try_from(&[1, 2, 3, 4]).unwrap();
444-
let rev = ShortData::try_from(&[4, 3, 2, 1]).unwrap();
445-
let trunc = ShortData::try_from(&[1, 2, 3]).unwrap();
443+
let msg = ShortData::from(&[1, 2, 3, 4]);
444+
let rev = ShortData::from(&[4, 3, 2, 1]);
445+
let trunc = ShortData::from(&[1, 2, 3]);
446446
run(runner::BACKENDS_MIXED, |client| {
447447
assert_eq!(trussed::syscall!(client.sample_calls()).calls, 0);
448448
assert_eq!(trussed::syscall!(client.test_calls()).calls, 0);

0 commit comments

Comments
 (0)