Skip to content

Commit

Permalink
schema: use pushdown-driven Veriform decoder
Browse files Browse the repository at this point in the history
Updates the handwritten decoder fields to use the new pushdown
automaton-based `Decoder` API which landed in:
iqlusioninc/veriform#117
  • Loading branch information
tony-iqlusion committed Apr 22, 2020
1 parent cf8759e commit 6dec16f
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 128 deletions.
132 changes: 129 additions & 3 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions client/src/armistice.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Armistice client
use crate::error::Error;
use armistice_schema::{Message, Request, Response};
use armistice_schema::{veriform::Decoder, Message, Request, Response};

#[cfg(feature = "usbarmory")]
use crate::usbarmory;
Expand All @@ -27,6 +27,8 @@ impl Armistice {

let mut buf = vec![0; self.usb.in_max_packet_size().into()];
let response = self.usb.read(&mut buf)?;
Ok(Response::decode(response)?)

let mut decoder = Decoder::new();
Ok(Response::decode(&mut decoder, response)?)
}
}
7 changes: 2 additions & 5 deletions core/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//!
//! <https://github.com/theupdateframework/specification/blob/master/tuf-spec.md#4-document-formats>
use crate::{crypto::PublicKey, error::Error, schema::provision::Uuid};
use crate::{crypto::PublicKey, error::Error, schema::Uuid};
use heapless::Vec;

/// Maximum number of keys allowed for root role
Expand Down Expand Up @@ -61,9 +61,6 @@ impl Config {
/// Get a UUID which represents this root configuration
pub fn uuid(&self) -> Uuid {
// TODO(tarcieri): stub!
let mut uuid = Uuid::new();
uuid.push_str("00000000-0000-0000-0000-000000000000")
.unwrap();
uuid
Uuid::parse_str("00000000-0000-0000-0000-000000000000").unwrap()
}
}
4 changes: 2 additions & 2 deletions core/tests/provision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use aes::{block_cipher_trait::BlockCipher, Aes128};
use armistice_core::Vec;
use armistice_schema::{provision, public_key::PublicKey};
use armistice_schema::{provision, public_key::PublicKey, Uuid};

type Armistice = armistice_core::Armistice<Aes128>;

Expand Down Expand Up @@ -42,6 +42,6 @@ fn provisioning_happy_path() {
// TODO(tarcieri): stub!
assert_eq!(
response.provision().unwrap().uuid,
"00000000-0000-0000-0000-000000000000"
Uuid::parse_str("00000000-0000-0000-0000-000000000000").unwrap()
);
}
6 changes: 5 additions & 1 deletion schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ keywords = ["bls", "ed25519", "ecdsa", "hsm"]

[dependencies]
heapless = "0.5"
veriform = { version = "0", default-features = false }
veriform = { version = "0", default-features = false, features = ["builtins"] }

[dev-dependencies]
veriform = { version = "0", default-features = false, features = ["builtins", "log"] }
env_logger = "0.7"

[package.metadata.docs.rs]
all-features = true
2 changes: 1 addition & 1 deletion schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ pub mod request;
pub mod response;

pub use self::{public_key::PublicKey, request::Request, response::Response};
pub use veriform::Message;
pub use veriform::{self, builtins::Uuid, Message};
Loading

0 comments on commit 6dec16f

Please sign in to comment.