Skip to content

Commit 1d48d10

Browse files
Formatted with cargo fmt. Used cleaner function map_err
1 parent e297b32 commit 1d48d10

10 files changed

Lines changed: 204 additions & 256 deletions

File tree

native/src/oberon/mod.rs

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ impl crate::Oberon {
2626
return Err(Error::InvalidField("must provide data"));
2727
}
2828

29-
let skbytes: [u8; oberon::SecretKey::BYTES] = match request.sk.as_slice().try_into() {
30-
Ok(skbytes) => skbytes,
31-
Err(_) => return Err(Error::InvalidField("invalid secret key provided")),
32-
};
29+
let skbytes: [u8; oberon::SecretKey::BYTES] = request
30+
.sk
31+
.as_slice()
32+
.try_into()
33+
.map_err(|_| Error::InvalidField("invalid secret key provided"))?;
3334

3435
let sk = oberon::SecretKey::from(&skbytes);
3536
let mut token = match oberon::Token::new(&sk, &request.data) {
@@ -53,10 +54,7 @@ impl crate::Oberon {
5354
return Err(Error::InvalidField("must provide data"));
5455
}
5556

56-
let tokenbytes: [u8; oberon::Token::BYTES] = match request.token.as_slice().try_into() {
57-
Ok(tokenbytes) => tokenbytes,
58-
Err(_) => return Err(Error::InvalidField("invalid token provided")),
59-
};
57+
let tokenbytes: [u8; oberon::Token::BYTES] = request.token.as_slice().try_into().map_err(|_| Error::InvalidField("invalid token provided"))?;
6058

6159
let tkn = oberon::Token::from_bytes(&tokenbytes);
6260
if tkn.is_none().into() {
@@ -82,20 +80,18 @@ impl crate::Oberon {
8280
return Err(Error::InvalidField("must provide data"));
8381
}
8482

85-
let pkbytes: [u8; oberon::PublicKey::BYTES] = match request.pk.as_slice().try_into() {
86-
Ok(pkbytes) => pkbytes,
87-
Err(_) => return Err(Error::InvalidField("invalid public key provided")),
88-
};
83+
let pkbytes: [u8; oberon::PublicKey::BYTES] = request
84+
.pk
85+
.as_slice()
86+
.try_into()
87+
.map_err(|_| Error::InvalidField("invalid public key provided"))?;
8988

9089
let pk = oberon::PublicKey::from_bytes(&pkbytes);
9190
if pk.is_none().into() {
9291
return Err(Error::InvalidField("invalid public key provided"));
9392
}
9493

95-
let proofbytes: [u8; oberon::Proof::BYTES] = match request.proof.as_slice().try_into() {
96-
Ok(proofbytes) => proofbytes,
97-
Err(_) => return Err(Error::InvalidField("invalid proof provided")),
98-
};
94+
let proofbytes: [u8; oberon::Proof::BYTES] = request.proof.as_slice().try_into().map_err(|_| Error::InvalidField("invalid proof provided"))?;
9995

10096
let proof = oberon::Proof::from_bytes(&proofbytes);
10197
if proof.is_none().into() {
@@ -108,10 +104,7 @@ impl crate::Oberon {
108104
}
109105

110106
pub fn blind<'a>(request: &BlindOberonTokenRequest) -> Result<BlindOberonTokenResponse, Error<'a>> {
111-
let tokenbytes: [u8; oberon::Token::BYTES] = match request.token.as_slice().try_into() {
112-
Ok(tokenbytes) => tokenbytes,
113-
Err(_) => return Err(Error::InvalidField("invalid token provided")),
114-
};
107+
let tokenbytes: [u8; oberon::Token::BYTES] = request.token.as_slice().try_into().map_err(|_| Error::InvalidField("invalid token provided"))?;
115108

116109
let tkn = oberon::Token::from_bytes(&tokenbytes);
117110
if tkn.is_none().into() {
@@ -132,10 +125,7 @@ impl crate::Oberon {
132125
}
133126

134127
pub fn unblind<'a>(request: &UnBlindOberonTokenRequest) -> Result<BlindOberonTokenResponse, Error<'a>> {
135-
let tokenbytes: [u8; oberon::Token::BYTES] = match request.token.as_slice().try_into() {
136-
Ok(tokenbytes) => tokenbytes,
137-
Err(_) => return Err(Error::InvalidField("invalid token provided")),
138-
};
128+
let tokenbytes: [u8; oberon::Token::BYTES] = request.token.as_slice().try_into().map_err(|_| Error::InvalidField("invalid token provided"))?;
139129

140130
let tkn = oberon::Token::from_bytes(&tokenbytes);
141131
if tkn.is_none().into() {
@@ -160,20 +150,18 @@ impl crate::Oberon {
160150
return Err(Error::InvalidField("must provide data"));
161151
}
162152

163-
let pkbytes: [u8; oberon::PublicKey::BYTES] = match request.pk.as_slice().try_into() {
164-
Ok(pkbytes) => pkbytes,
165-
Err(_) => return Err(Error::InvalidField("invalid public key provided")),
166-
};
153+
let pkbytes: [u8; oberon::PublicKey::BYTES] = request
154+
.pk
155+
.as_slice()
156+
.try_into()
157+
.map_err(|_| Error::InvalidField("invalid public key provided"))?;
167158

168159
let pk = oberon::PublicKey::from_bytes(&pkbytes);
169160
if pk.is_none().into() {
170161
return Err(Error::InvalidField("invalid public key provided"));
171162
}
172163

173-
let tokenbytes = match request.token.as_slice().try_into() {
174-
Ok(tokenbytes) => tokenbytes,
175-
Err(_) => return Err(Error::InvalidField("invalid token provided")),
176-
};
164+
let tokenbytes: [u8; oberon::Token::BYTES] = request.token.as_slice().try_into().map_err(|_| Error::InvalidField("invalid token provided"))?;
177165

178166
let tkn = oberon::Token::from_bytes(&tokenbytes);
179167
if tkn.is_none().into() {
@@ -185,8 +173,6 @@ impl crate::Oberon {
185173
let verify_result = tkn.verify(pk, &request.data);
186174
let is_valid = bool::from(verify_result);
187175

188-
Ok(VerifyOberonTokenResponse {
189-
valid: is_valid
190-
})
176+
Ok(VerifyOberonTokenResponse { valid: is_valid })
191177
}
192178
}

native/src/proto/google_protobuf.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#[derive(Clone, PartialEq, ::prost::Message)]
1010
pub struct Struct {
1111
/// Unordered map of dynamically typed values.
12-
#[prost(map="string, message", tag="1")]
12+
#[prost(map = "string, message", tag = "1")]
1313
pub fields: ::std::collections::HashMap<::prost::alloc::string::String, Value>,
1414
}
1515
/// `Value` represents a dynamically typed value which can be either
@@ -21,7 +21,7 @@ pub struct Struct {
2121
#[derive(Clone, PartialEq, ::prost::Message)]
2222
pub struct Value {
2323
/// The kind of value.
24-
#[prost(oneof="value::Kind", tags="1, 2, 3, 4, 5, 6")]
24+
#[prost(oneof = "value::Kind", tags = "1, 2, 3, 4, 5, 6")]
2525
pub kind: ::core::option::Option<value::Kind>,
2626
}
2727
/// Nested message and enum types in `Value`.
@@ -30,22 +30,22 @@ pub mod value {
3030
#[derive(Clone, PartialEq, ::prost::Oneof)]
3131
pub enum Kind {
3232
/// Represents a null value.
33-
#[prost(enumeration="super::NullValue", tag="1")]
33+
#[prost(enumeration = "super::NullValue", tag = "1")]
3434
NullValue(i32),
3535
/// Represents a double value.
36-
#[prost(double, tag="2")]
36+
#[prost(double, tag = "2")]
3737
NumberValue(f64),
3838
/// Represents a string value.
39-
#[prost(string, tag="3")]
39+
#[prost(string, tag = "3")]
4040
StringValue(::prost::alloc::string::String),
4141
/// Represents a boolean value.
42-
#[prost(bool, tag="4")]
42+
#[prost(bool, tag = "4")]
4343
BoolValue(bool),
4444
/// Represents a structured value.
45-
#[prost(message, tag="5")]
45+
#[prost(message, tag = "5")]
4646
StructValue(super::Struct),
4747
/// Represents a repeated `Value`.
48-
#[prost(message, tag="6")]
48+
#[prost(message, tag = "6")]
4949
ListValue(super::ListValue),
5050
}
5151
}
@@ -55,7 +55,7 @@ pub mod value {
5555
#[derive(Clone, PartialEq, ::prost::Message)]
5656
pub struct ListValue {
5757
/// Repeated field of dynamically typed values.
58-
#[prost(message, repeated, tag="1")]
58+
#[prost(message, repeated, tag = "1")]
5959
pub values: ::prost::alloc::vec::Vec<Value>,
6060
}
6161
/// `NullValue` is a singleton enumeration to represent the null value for the
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#[derive(::serde::Serialize, ::serde::Deserialize)]
2-
#[derive(Clone, PartialEq, ::prost::Message)]
1+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
32
pub struct BasicMessage {
4-
#[prost(string, tag="1")]
3+
#[prost(string, tag = "1")]
54
pub text: ::prost::alloc::string::String,
65
}
Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,44 @@
1-
#[derive(::serde::Serialize, ::serde::Deserialize)]
2-
#[derive(Clone, PartialEq, ::prost::Message)]
1+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
32
pub struct Blake3HashRequest {
4-
#[prost(bytes="vec", tag="1")]
3+
#[prost(bytes = "vec", tag = "1")]
54
pub data: ::prost::alloc::vec::Vec<u8>,
65
}
7-
#[derive(::serde::Serialize, ::serde::Deserialize)]
8-
#[derive(Clone, PartialEq, ::prost::Message)]
6+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
97
pub struct Blake3HashResponse {
10-
#[prost(bytes="vec", tag="1")]
8+
#[prost(bytes = "vec", tag = "1")]
119
pub digest: ::prost::alloc::vec::Vec<u8>,
1210
}
13-
#[derive(::serde::Serialize, ::serde::Deserialize)]
14-
#[derive(Clone, PartialEq, ::prost::Message)]
11+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
1512
pub struct Blake3KeyedHashRequest {
16-
#[prost(bytes="vec", tag="1")]
13+
#[prost(bytes = "vec", tag = "1")]
1714
pub data: ::prost::alloc::vec::Vec<u8>,
18-
#[prost(bytes="vec", tag="2")]
15+
#[prost(bytes = "vec", tag = "2")]
1916
pub key: ::prost::alloc::vec::Vec<u8>,
2017
}
21-
#[derive(::serde::Serialize, ::serde::Deserialize)]
22-
#[derive(Clone, PartialEq, ::prost::Message)]
18+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
2319
pub struct Blake3KeyedHashResponse {
24-
#[prost(bytes="vec", tag="1")]
20+
#[prost(bytes = "vec", tag = "1")]
2521
pub digest: ::prost::alloc::vec::Vec<u8>,
2622
}
27-
#[derive(::serde::Serialize, ::serde::Deserialize)]
28-
#[derive(Clone, PartialEq, ::prost::Message)]
23+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
2924
pub struct Blake3DeriveKeyRequest {
30-
#[prost(bytes="vec", tag="1")]
25+
#[prost(bytes = "vec", tag = "1")]
3126
pub context: ::prost::alloc::vec::Vec<u8>,
32-
#[prost(bytes="vec", tag="2")]
27+
#[prost(bytes = "vec", tag = "2")]
3328
pub key_material: ::prost::alloc::vec::Vec<u8>,
3429
}
35-
#[derive(::serde::Serialize, ::serde::Deserialize)]
36-
#[derive(Clone, PartialEq, ::prost::Message)]
30+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
3731
pub struct Blake3DeriveKeyResponse {
38-
#[prost(bytes="vec", tag="1")]
32+
#[prost(bytes = "vec", tag = "1")]
3933
pub digest: ::prost::alloc::vec::Vec<u8>,
4034
}
41-
#[derive(::serde::Serialize, ::serde::Deserialize)]
42-
#[derive(Clone, PartialEq, ::prost::Message)]
35+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
4336
pub struct Sha256HashRequest {
44-
#[prost(bytes="vec", tag="1")]
37+
#[prost(bytes = "vec", tag = "1")]
4538
pub data: ::prost::alloc::vec::Vec<u8>,
4639
}
47-
#[derive(::serde::Serialize, ::serde::Deserialize)]
48-
#[derive(Clone, PartialEq, ::prost::Message)]
40+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
4941
pub struct Sha256HashResponse {
50-
#[prost(bytes="vec", tag="1")]
42+
#[prost(bytes = "vec", tag = "1")]
5143
pub digest: ::prost::alloc::vec::Vec<u8>,
5244
}

native/src/proto/okapi/okapi_keys.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,48 @@
1-
#[derive(::serde::Serialize, ::serde::Deserialize)]
2-
#[derive(Clone, PartialEq, ::prost::Message)]
1+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
32
pub struct GenerateKeyRequest {
4-
#[prost(bytes="vec", tag="1")]
3+
#[prost(bytes = "vec", tag = "1")]
54
pub seed: ::prost::alloc::vec::Vec<u8>,
6-
#[prost(enumeration="KeyType", tag="2")]
5+
#[prost(enumeration = "KeyType", tag = "2")]
76
pub key_type: i32,
87
}
9-
#[derive(::serde::Serialize, ::serde::Deserialize)]
10-
#[derive(Clone, PartialEq, ::prost::Message)]
8+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
119
pub struct GenerateKeyResponse {
12-
#[prost(message, repeated, tag="1")]
10+
#[prost(message, repeated, tag = "1")]
1311
pub key: ::prost::alloc::vec::Vec<JsonWebKey>,
14-
#[prost(message, optional, tag="2")]
12+
#[prost(message, optional, tag = "2")]
1513
pub did_document: ::core::option::Option<super::super::super::google::protobuf::Struct>,
1614
}
17-
#[derive(::serde::Serialize, ::serde::Deserialize)]
18-
#[derive(Clone, PartialEq, ::prost::Message)]
15+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
1916
pub struct ResolveRequest {
20-
#[prost(string, tag="1")]
17+
#[prost(string, tag = "1")]
2118
pub did: ::prost::alloc::string::String,
2219
}
23-
#[derive(::serde::Serialize, ::serde::Deserialize)]
24-
#[derive(Clone, PartialEq, ::prost::Message)]
20+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
2521
pub struct ResolveResponse {
26-
#[prost(message, optional, tag="1")]
22+
#[prost(message, optional, tag = "1")]
2723
pub did_document: ::core::option::Option<super::super::super::google::protobuf::Struct>,
28-
#[prost(message, repeated, tag="2")]
24+
#[prost(message, repeated, tag = "2")]
2925
pub keys: ::prost::alloc::vec::Vec<JsonWebKey>,
3026
}
31-
#[derive(::serde::Serialize, ::serde::Deserialize)]
32-
#[derive(Clone, PartialEq, ::prost::Message)]
27+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
3328
pub struct JsonWebKey {
34-
#[prost(string, tag="1")]
29+
#[prost(string, tag = "1")]
3530
pub kid: ::prost::alloc::string::String,
3631
/// public_key
37-
#[prost(string, tag="2")]
32+
#[prost(string, tag = "2")]
3833
pub x: ::prost::alloc::string::String,
3934
/// public_key
40-
#[prost(string, tag="3")]
35+
#[prost(string, tag = "3")]
4136
pub y: ::prost::alloc::string::String,
4237
/// secret_key
43-
#[prost(string, tag="4")]
38+
#[prost(string, tag = "4")]
4439
pub d: ::prost::alloc::string::String,
45-
#[prost(string, tag="5")]
40+
#[prost(string, tag = "5")]
4641
pub crv: ::prost::alloc::string::String,
47-
#[prost(string, tag="6")]
42+
#[prost(string, tag = "6")]
4843
pub kty: ::prost::alloc::string::String,
4944
}
50-
#[derive(::serde::Serialize, ::serde::Deserialize)]
51-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
45+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
5246
#[repr(i32)]
5347
pub enum KeyType {
5448
Unspecified = 0,

native/src/proto/okapi/okapi_proofs.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
1-
#[derive(::serde::Serialize, ::serde::Deserialize)]
2-
#[derive(Clone, PartialEq, ::prost::Message)]
1+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
32
pub struct CreateProofRequest {
43
/// The input JSON document that will be used
54
/// to create the LD Proof. This document must
65
/// also contain a "proof" object, with the desired
76
/// values filled in.
8-
#[prost(message, optional, tag="1")]
7+
#[prost(message, optional, tag = "1")]
98
pub document: ::core::option::Option<super::super::super::google::protobuf::Struct>,
109
/// The signer of the proof. This field must include
1110
/// the 'kid' in full URI format.
1211
/// Example:
1312
/// did:example:alice#key-1
14-
#[prost(message, optional, tag="3")]
13+
#[prost(message, optional, tag = "3")]
1514
pub key: ::core::option::Option<super::super::keys::v1::JsonWebKey>,
1615
/// The LD Suite to use to produce this proof
17-
#[prost(enumeration="LdSuite", tag="4")]
16+
#[prost(enumeration = "LdSuite", tag = "4")]
1817
pub suite: i32,
1918
}
20-
#[derive(::serde::Serialize, ::serde::Deserialize)]
21-
#[derive(Clone, PartialEq, ::prost::Message)]
19+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
2220
pub struct CreateProofResponse {
23-
#[prost(message, optional, tag="1")]
21+
#[prost(message, optional, tag = "1")]
2422
pub signed_document: ::core::option::Option<super::super::super::google::protobuf::Struct>,
2523
}
26-
#[derive(::serde::Serialize, ::serde::Deserialize)]
27-
#[derive(Clone, PartialEq, ::prost::Message)]
28-
pub struct VerifyProofRequest {
29-
}
30-
#[derive(::serde::Serialize, ::serde::Deserialize)]
31-
#[derive(Clone, PartialEq, ::prost::Message)]
32-
pub struct VerifyProofResponse {
33-
}
34-
#[derive(::serde::Serialize, ::serde::Deserialize)]
35-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
24+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
25+
pub struct VerifyProofRequest {}
26+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, PartialEq, ::prost::Message)]
27+
pub struct VerifyProofResponse {}
28+
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
3629
#[repr(i32)]
3730
pub enum LdSuite {
3831
Unspecified = 0,

0 commit comments

Comments
 (0)