-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
udate dependencies and make examples work #1
Open
tyrchen
wants to merge
1
commit into
withoutboats:master
Choose a base branch
from
tyrchen:feature/make-project-up-to-date
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
cargo-features = ["edition"] | ||
|
||
[package] | ||
authors = ["Without Boats <[email protected]>"] | ||
description = "bridge non-PGP system to PGP data format" | ||
|
@@ -11,21 +9,42 @@ version = "0.4.0" | |
repository = "https://github.com/withoutboats/pbp" | ||
|
||
[dependencies] | ||
base64 = "0.9.2" | ||
byteorder = "1.1.0" | ||
digest = "0.7.0" | ||
sha1 = "0.2.0" | ||
typenum = "1.9.0" | ||
failure = "0.1.1" | ||
bitflags = "1.0.1" | ||
base64 = "0.11" | ||
byteorder = "1" | ||
digest = "0.8" | ||
sha1 = "0.6" | ||
typenum = "1.11" | ||
failure = "0.1" | ||
bitflags = "1.2" | ||
rand = "0.6" | ||
sha2 = "0.8" | ||
|
||
[dependencies.ed25519-dalek] | ||
version = "0.7.0" | ||
version = "0.9" | ||
optional = true | ||
|
||
[features] | ||
dalek = ["ed25519-dalek"] | ||
|
||
[dev-dependencies] | ||
rand = "0.5.4" | ||
sha2 = "0.6.0" | ||
ed25519-dalek = "0.9" | ||
|
||
[[example]] | ||
required-features = ["dalek"] | ||
name = "print" | ||
path = "examples/print.rs" | ||
|
||
[[example]] | ||
required-features = ["dalek"] | ||
name = "read_sig" | ||
path = "examples/read_sig.rs" | ||
|
||
[[example]] | ||
required-features = ["dalek"] | ||
name = "round_trip" | ||
path = "examples/round_trip.rs" | ||
|
||
[[example]] | ||
required-features = ["dalek"] | ||
name = "verify_sig" | ||
path = "examples/verify_sig.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,30 @@ | ||
extern crate rand; | ||
extern crate sha2; | ||
extern crate ed25519_dalek as dalek; | ||
extern crate pbp; | ||
extern crate rand; | ||
extern crate sha2; | ||
|
||
use std::time::SystemTime; | ||
|
||
use rand::OsRng; | ||
use sha2::{Sha256, Sha512}; | ||
use dalek::Keypair; | ||
use pbp::{PgpKey, KeyFlags}; | ||
use failure::Error; | ||
use pbp::{KeyFlags, PgpKey}; | ||
use rand::rngs::OsRng; | ||
use sha2::{Sha256, Sha512}; | ||
|
||
fn main() { | ||
fn main() -> Result<(), Error> { | ||
let mut cspring = OsRng::new().unwrap(); | ||
let keypair = Keypair::generate::<Sha512>(&mut cspring); | ||
let keypair = Keypair::generate::<Sha512, _>(&mut cspring); | ||
let timestamp = SystemTime::now() | ||
.duration_since(SystemTime::UNIX_EPOCH)? | ||
.as_secs(); | ||
|
||
let key = PgpKey::from_dalek::<Sha256, Sha512>(&keypair, KeyFlags::NONE, "withoutboats"); | ||
let key = PgpKey::from_dalek::<Sha256, Sha512>( | ||
&keypair, | ||
KeyFlags::NONE, | ||
timestamp as u32, | ||
"withoutboats", | ||
); | ||
println!("{}", key); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,45 @@ | ||
extern crate rand; | ||
extern crate sha2; | ||
extern crate ed25519_dalek as dalek; | ||
extern crate pbp; | ||
extern crate rand; | ||
extern crate sha2; | ||
|
||
use std::time::SystemTime; | ||
|
||
use rand::OsRng; | ||
use sha2::{Sha256, Sha512}; | ||
use dalek::Keypair; | ||
use pbp::{PgpKey, PgpSig, SigType, KeyFlags}; | ||
use failure::Error; | ||
use pbp::{KeyFlags, PgpKey, PgpSig, SigType}; | ||
use rand::rngs::OsRng; | ||
use sha2::Digest; | ||
use sha2::{Sha256, Sha512}; | ||
|
||
const DATA: &[u8] = b"How will I ever get out of this labyrinth?"; | ||
|
||
fn main() { | ||
fn main() -> Result<(), Error> { | ||
let mut cspring = OsRng::new().unwrap(); | ||
let keypair = Keypair::generate::<Sha512>(&mut cspring); | ||
|
||
let key = PgpKey::from_dalek::<Sha256, Sha512>(&keypair, KeyFlags::SIGN, "withoutboats"); | ||
let sig = PgpSig::from_dalek::<Sha256, Sha512>(&keypair, DATA, key.fingerprint(), SigType::BinaryDocument); | ||
if sig.verify_dalek::<Sha256, Sha512>(DATA, &keypair.public) { | ||
let keypair = Keypair::generate::<Sha512, _>(&mut cspring); | ||
let timestamp = SystemTime::now() | ||
.duration_since(SystemTime::UNIX_EPOCH)? | ||
.as_secs(); | ||
let key = PgpKey::from_dalek::<sha2::Sha256, sha2::Sha512>( | ||
&keypair, | ||
KeyFlags::NONE, | ||
timestamp as u32, | ||
"withoutboats", | ||
); | ||
let sig = PgpSig::from_dalek::<Sha256, Sha512>( | ||
&keypair, | ||
DATA, | ||
key.fingerprint(), | ||
SigType::BinaryDocument, | ||
timestamp as u32, | ||
); | ||
if sig.verify_dalek::<Sha256, Sha512, _>(&keypair.public, |hasher| { | ||
hasher.input(DATA); | ||
}) { | ||
println!("Verified successfully."); | ||
} else { | ||
println!("Could not verify."); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,11 @@ impl From<base64::DecodeError> for PgpError { | |
} | ||
|
||
// Convert from an ASCII armored string into binary data. | ||
pub fn remove_ascii_armor(s: &str, expected_header: &str, expected_footer: &str) -> Result<Vec<u8>, PgpError> { | ||
pub fn remove_ascii_armor( | ||
s: &str, | ||
expected_header: &str, | ||
expected_footer: &str, | ||
) -> Result<Vec<u8>, PgpError> { | ||
let lines: Vec<&str> = s.lines().map(|s| s.trim()).collect(); | ||
let header = lines.first().ok_or(InvalidAsciiArmor)?; | ||
let footer = lines.last().ok_or(InvalidAsciiArmor)?; | ||
|
@@ -28,51 +32,51 @@ pub fn remove_ascii_armor(s: &str, expected_header: &str, expected_footer: &str) | |
|| header.trim_matches('-').trim() != expected_header | ||
|| footer.trim_matches('-').trim() != expected_footer | ||
{ | ||
return Err(InvalidAsciiArmor) | ||
return Err(InvalidAsciiArmor); | ||
} | ||
|
||
// Find the end of the header section | ||
let end_of_headers = 1 + lines.iter().take_while(|l| !l.is_empty()).count(); | ||
if end_of_headers >= lines.len() - 2 { return Err(InvalidAsciiArmor) } | ||
if end_of_headers >= lines.len() - 2 { | ||
return Err(InvalidAsciiArmor); | ||
} | ||
|
||
// Decode the base64'd data | ||
let ascii_armored: String = lines[end_of_headers..lines.len() - 2].concat(); | ||
let data = base64::decode(&ascii_armored)?; | ||
|
||
// Confirm checksum | ||
let cksum_line = &lines[lines.len() - 2]; | ||
if !cksum_line.starts_with("=") || !cksum_line.len() > 1 { | ||
return Err(InvalidAsciiArmor) | ||
|
||
if !cksum_line.starts_with("=") || !(cksum_line.len() > 1) { | ||
return Err(InvalidAsciiArmor); | ||
} | ||
let mut cksum = [0; 4]; | ||
base64::decode_config_slice(&cksum_line[1..], base64::STANDARD, &mut cksum[..])?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initially, I can't get this work against |
||
base64::decode_config_slice(&cksum_line[1..], base64::URL_SAFE, &mut cksum[1..])?; | ||
let mut cksum_buf = [0; 4]; | ||
BigEndian::write_u32(&mut cksum_buf, checksum_crc24(&data)); | ||
|
||
if BigEndian::read_u32(&cksum[..]) != checksum_crc24(&data) { | ||
return Err(InvalidAsciiArmor) | ||
return Err(InvalidAsciiArmor); | ||
} | ||
|
||
Ok(data) | ||
} | ||
} | ||
|
||
// Ascii armors data into the formatter | ||
pub fn ascii_armor( | ||
header: &'static str, | ||
footer: &'static str, | ||
data: &[u8], | ||
f: &mut fmt::Formatter | ||
) -> fmt::Result | ||
{ | ||
data: &[u8], | ||
f: &mut fmt::Formatter, | ||
) -> fmt::Result { | ||
// Header Line | ||
f.write_str("-----")?; | ||
f.write_str(header)?; | ||
f.write_str("-----\n\n")?; | ||
|
||
// Base64'd data | ||
let b64_cfg = base64::Config::new( | ||
base64::CharacterSet::Standard, | ||
true, | ||
false, | ||
base64::LineWrap::Wrap(76, base64::LineEnding::LF), | ||
); | ||
let b64_cfg = base64::Config::new(base64::CharacterSet::Standard, true); | ||
f.write_str(&base64::encode_config(data, b64_cfg))?; | ||
f.write_str("\n=")?; | ||
|
||
|
@@ -101,7 +105,6 @@ fn checksum_crc24(data: &[u8]) -> u32 { | |
crc ^= (byte as u32) << 16; | ||
|
||
for _ in 0..8 { | ||
|
||
crc <<= 1; | ||
|
||
if (crc & 0x_0100_0000) != 0 { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like we need a () here for
cksum_line.len() > 1