Skip to content

Commit

Permalink
build(deps): bump pem to 3.0
Browse files Browse the repository at this point in the history
replaces comit-network#1415

also fixes the `seed_from_pem_fails_for_long_seed` unit test, which was
"passing" but not actually testing what it meant to.
  • Loading branch information
delta1 committed Oct 23, 2023
1 parent 04e618f commit dcf9f24
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion swap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ itertools = "0.10"
libp2p = { version = "0.42.2", default-features = false, features = [ "tcp-tokio", "yamux", "mplex", "dns-tokio", "noise", "request-response", "websocket", "ping", "rendezvous", "identify" ] }
monero = { version = "0.12", features = [ "serde_support" ] }
monero-rpc = { path = "../monero-rpc" }
pem = "1.1"
pem = "3.0"
proptest = "1"
qrcode = "0.12"
rand = "0.8"
Expand Down
21 changes: 10 additions & 11 deletions swap/src/seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ impl Seed {
}

fn from_pem(pem: pem::Pem) -> Result<Self, Error> {
if pem.contents.len() != SEED_LENGTH {
Err(Error::IncorrectLength(pem.contents.len()))
let contents = pem.contents();
if contents.len() != SEED_LENGTH {
Err(Error::IncorrectLength(contents.len()))
} else {
let mut array = [0; SEED_LENGTH];
for (i, b) in pem.contents.iter().enumerate() {
for (i, b) in contents.iter().enumerate() {
array[i] = *b;
}

Expand All @@ -122,10 +123,7 @@ impl Seed {
ensure_directory_exists(&seed_file)?;

let data = self.bytes();
let pem = Pem {
tag: String::from("SEED"),
contents: data.to_vec(),
};
let pem = Pem::new("SEED", data);

let pem_string = encode(&pem);

Expand Down Expand Up @@ -224,19 +222,20 @@ VnZUNFZ4dlY=
}

#[test]
#[should_panic]
fn seed_from_pem_fails_for_long_seed() {
let long = "-----BEGIN SEED-----
mbKANv2qKGmNVg1qtquj6Hx1pFPelpqOfE2JaJJAMEg1FlFhNRNlFlE=
mbKANv2qKGmNVg1qtquj6Hx1pFPelpqOfE2JaJJAMEg1FlFhNRNlFlE=
MIIBPQIBAAJBAOsfi5AGYhdRs/x6q5H7kScxA0Kzzqe6WI6gf6+tc6IvKQJo5rQc
dWWSQ0nRGt2hOPDO+35NKhQEjBQxPh/v7n0CAwEAAQJBAOGaBAyuw0ICyENy5NsO
-----END SEED-----
";
let pem = pem::parse(long).unwrap();
assert_eq!(pem.contents().len(), 96);

match Seed::from_pem(pem) {
Ok(_) => panic!("should fail for long payload"),
Err(e) => {
match e {
Error::IncorrectLength(_) => {} // pass
Error::IncorrectLength(len) => assert_eq!(len, 96), // pass
_ => panic!("should fail with IncorrectLength error"),
}
}
Expand Down

0 comments on commit dcf9f24

Please sign in to comment.