Compare commits
11 Commits
0.4.0
...
serde_cbor
Author | SHA1 | Date | |
---|---|---|---|
5bf210dc73
|
|||
0a2a054233
|
|||
c358202a3a
|
|||
86649b56aa
|
|||
48604d165b
|
|||
317f5ebdb4
|
|||
33229a0b3c
|
|||
9737a006e7
|
|||
d6b20d0ba4
|
|||
857c3cd955
|
|||
80c175077f
|
24
.drone.yml
Normal file
24
.drone.yml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
kind: pipeline
|
||||||
|
name: default
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: fmt
|
||||||
|
image: rust:1.43.0
|
||||||
|
commands:
|
||||||
|
- rustup component add rustfmt
|
||||||
|
- cargo fmt --all -- --check
|
||||||
|
- name: test
|
||||||
|
image: rust:1.43.0
|
||||||
|
commands:
|
||||||
|
- cargo test --all-features
|
||||||
|
- name: publish
|
||||||
|
image: rust:1.43.0
|
||||||
|
environment:
|
||||||
|
CARGO_REGISTRY_TOKEN:
|
||||||
|
from_secret: cargo_tkn
|
||||||
|
commands:
|
||||||
|
- grep -E 'version ?= ?"${DRONE_TAG}"' -i Cargo.toml || (printf "incorrect crate/tag version" && exit 1)
|
||||||
|
- cargo package --all-features
|
||||||
|
- cargo publish --all-features
|
||||||
|
when:
|
||||||
|
event: tag
|
@@ -23,6 +23,10 @@ rust-crypto = "0.2"
|
|||||||
csv-core = "0.1.6"
|
csv-core = "0.1.6"
|
||||||
derive_builder = "0.9.0"
|
derive_builder = "0.9.0"
|
||||||
crossbeam = { version = "0.7.3", optional = true }
|
crossbeam = { version = "0.7.3", optional = true }
|
||||||
|
serde_derive = "1.0.106"
|
||||||
|
serde = "1.0.106"
|
||||||
|
serde_cbor = "0.11.1"
|
||||||
|
serde_bytes = "0.11.3"
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
crossbeam = "0.7.3"
|
crossbeam = "0.7.3"
|
||||||
hex = "0.4.0"
|
hex = "0.4.0"
|
||||||
|
@@ -24,6 +24,7 @@ fn main() -> ctap::FidoResult<()> {
|
|||||||
FidoDevice::new(&h).and_then(|mut dev| {
|
FidoDevice::new(&h).and_then(|mut dev| {
|
||||||
FidoCredentialRequestBuilder::default()
|
FidoCredentialRequestBuilder::default()
|
||||||
.rp_id(RP_ID)
|
.rp_id(RP_ID)
|
||||||
|
.user_name("test")
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.make_credential(&mut dev)
|
.make_credential(&mut dev)
|
||||||
|
45
src/cbor.rs
45
src/cbor.rs
@@ -597,14 +597,45 @@ impl CoseKey {
|
|||||||
let mut cose_key = CoseKey::default();
|
let mut cose_key = CoseKey::default();
|
||||||
cose_key.algorithm = -7;
|
cose_key.algorithm = -7;
|
||||||
for _ in 0..items {
|
for _ in 0..items {
|
||||||
match generic.borrow_mut().i16()? {
|
match generic.value()? {
|
||||||
0x01 => cose_key.key_type = generic.borrow_mut().u16()?,
|
Value::Text(value::Text::Text(text)) => match &text[..] {
|
||||||
0x02 => cose_key.algorithm = generic.borrow_mut().i32()?,
|
"type" => {
|
||||||
key if key < 0 => {
|
cose_key.key_type = match generic.value()? {
|
||||||
cose_key.parameters.insert(key, generic.value()?);
|
Value::Text(value::Text::Text(type_)) if &type_ == "public-key" => 0u16,
|
||||||
|
Value::U16(i) => i,
|
||||||
|
Value::U8(i) => i.into(),
|
||||||
|
_ => {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"alg" => cose_key.algorithm = generic.borrow_mut().i32()?,
|
||||||
|
_ => continue,
|
||||||
|
},
|
||||||
|
val @ Value::I8(_)
|
||||||
|
| val @ Value::I16(_)
|
||||||
|
| val @ Value::U16(_)
|
||||||
|
| val @ Value::U8(_) => {
|
||||||
|
let int_val = match val {
|
||||||
|
Value::I8(i) => i as i32,
|
||||||
|
Value::I16(i) => i as i32,
|
||||||
|
Value::U8(i) => i as i32,
|
||||||
|
Value::U16(i) => i as i32,
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
match int_val {
|
||||||
|
0x01 => cose_key.key_type = generic.borrow_mut().u16()?,
|
||||||
|
0x02 => cose_key.algorithm = generic.borrow_mut().i32()?,
|
||||||
|
key if key < 0 => {
|
||||||
|
cose_key.parameters.insert(key as i16, generic.value()?);
|
||||||
|
}
|
||||||
|
unknown => {
|
||||||
|
(unknown, generic.value()?); // skip unknown parameter
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
unknown => {
|
||||||
generic.value()?; // skip unknown parameter
|
(unknown, generic.value()?); // skip unknown parameter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1279
src/protocol/cbor.rs
Normal file
1279
src/protocol/cbor.rs
Normal file
File diff suppressed because it is too large
Load Diff
7
src/protocol/error.rs
Normal file
7
src/protocol/error.rs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
|
pub enum ProtocolError {
|
||||||
|
CborEncode,
|
||||||
|
CborDecode { data: Vec<u8> },
|
||||||
|
}
|
4
src/protocol/mod.rs
Normal file
4
src/protocol/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
mod cbor;
|
||||||
|
mod error;
|
||||||
|
pub use self::cbor::*;
|
||||||
|
pub use self::error::*;
|
9
src/transport/mod.rs
Normal file
9
src/transport/mod.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
use crate::protocol::{CborRequest, CborResponse};
|
||||||
|
|
||||||
|
pub trait CtapTransport {
|
||||||
|
type Error;
|
||||||
|
|
||||||
|
fn cbor<'a>(&mut self, command: &CborRequest<'a>) -> Result<CborResponse, Self::Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum CtapCommand {}
|
28
src/util.rs
28
src/util.rs
@@ -33,25 +33,23 @@ pub fn request_multiple_devices<
|
|||||||
let interval = Duration::from_millis(10);
|
let interval = Duration::from_millis(10);
|
||||||
let mut received = 0usize;
|
let mut received = 0usize;
|
||||||
let res = loop {
|
let res = loop {
|
||||||
if timeout.map(|t| t < slept).unwrap_or(true) {
|
match timeout {
|
||||||
break if let Some(cause) = err {
|
Some(t) if t < slept => {
|
||||||
cause
|
break if let Some(cause) = err {
|
||||||
} else {
|
cause
|
||||||
Err(FidoErrorKind::Timeout.into())
|
} else {
|
||||||
};
|
Err(FidoErrorKind::Timeout.into())
|
||||||
}
|
};
|
||||||
if received == handles.len() {
|
}
|
||||||
break err.unwrap();
|
_ => (),
|
||||||
}
|
}
|
||||||
|
if timeout.map(|t| t < slept).unwrap_or(true) {}
|
||||||
if let Ok(msg) = rx.recv_timeout(interval) {
|
if let Ok(msg) = rx.recv_timeout(interval) {
|
||||||
received += 1;
|
received += 1;
|
||||||
match msg {
|
match msg {
|
||||||
e @ Err(_) => {
|
e @ Err(_) if received == handles.len() => break e,
|
||||||
err = Some(e);
|
e @ Err(_) => err = Some(e),
|
||||||
}
|
res @ Ok(_) => break res,
|
||||||
res @ Ok(_) => {
|
|
||||||
break res;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
slept += interval;
|
slept += interval;
|
||||||
|
Reference in New Issue
Block a user