Skip to content

Commit c822ff7

Browse files
committed
move Uuid impl to seprate mod
1 parent 597230c commit c822ff7

File tree

6 files changed

+41
-37
lines changed

6 files changed

+41
-37
lines changed

rust/vote-tx-v2/src/gen_tx/builder.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
use anyhow::ensure;
44

55
use super::{
6-
cose_protected_header, EncodedCbor, EventKey, EventMap, GeneralizedTx, TxBody, Uuid, Vote,
7-
VoterData,
6+
cose_protected_header, EncodedCbor, EventKey, EventMap, GeneralizedTx, TxBody, Vote, VoterData,
87
};
9-
use crate::Cbor;
8+
use crate::{uuid::Uuid, Cbor};
109

1110
/// `GeneralizedTx` builder struct
1211
#[allow(clippy::module_name_repetitions)]

rust/vote-tx-v2/src/gen_tx/mod.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,11 @@ where
3232
signature: coset::CoseSign,
3333
}
3434

35-
/// A UUID struct, CBOR tag 37.
36-
#[derive(Debug, Clone, PartialEq)]
37-
pub struct Uuid(pub Vec<u8>);
38-
3935
/// An encoded CBOR struct, CBOR tag 24.
4036
#[derive(Debug, Clone, PartialEq)]
4137
pub struct EncodedCbor<T>(T)
4238
where T: for<'a> Cbor<'a>;
4339

44-
/// UUID CBOR tag <https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml/>.
45-
const UUID_TAG: u64 = 37;
46-
4740
/// encoded-cbor CBOR tag <https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml/>.
4841
const ENCODED_CBOR_TAG: u64 = 24;
4942

@@ -116,30 +109,6 @@ where
116109
}
117110
}
118111

119-
impl Decode<'_, ()> for Uuid {
120-
fn decode(d: &mut Decoder<'_>, (): &mut ()) -> Result<Self, minicbor::decode::Error> {
121-
let tag = d.tag()?;
122-
if UUID_TAG != tag.as_u64() {
123-
return Err(minicbor::decode::Error::message(format!(
124-
"tag value must be: {UUID_TAG}, provided: {}",
125-
tag.as_u64(),
126-
)));
127-
}
128-
let choice = d.bytes()?.to_vec();
129-
Ok(Self(choice))
130-
}
131-
}
132-
133-
impl Encode<()> for Uuid {
134-
fn encode<W: minicbor::encode::Write>(
135-
&self, e: &mut minicbor::Encoder<W>, (): &mut (),
136-
) -> Result<(), minicbor::encode::Error<W::Error>> {
137-
e.tag(Tag::new(UUID_TAG))?;
138-
e.bytes(&self.0)?;
139-
Ok(())
140-
}
141-
}
142-
143112
impl<T> Decode<'_, ()> for EncodedCbor<T>
144113
where T: for<'a> Cbor<'a>
145114
{
@@ -200,6 +169,7 @@ mod tests {
200169
use test_strategy::proptest;
201170

202171
use super::*;
172+
use crate::uuid::Uuid;
203173

204174
type ChoiceT = Vec<u8>;
205175
type ProofT = Vec<u8>;

rust/vote-tx-v2/src/gen_tx/tx_body.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use minicbor::{Decode, Decoder, Encode, Encoder};
44

5-
use super::{EncodedCbor, EventMap, Uuid, Vote};
6-
use crate::Cbor;
5+
use super::{EncodedCbor, EventMap, Vote};
6+
use crate::{uuid::Uuid, Cbor};
77

88
/// `TxBody` array struct length
99
const TX_BODY_LEN: u64 = 4;

rust/vote-tx-v2/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use minicbor::{Decode, Decoder, Encode, Encoder};
88

99
pub mod gen_tx;
1010
pub mod public_tx;
11+
pub mod uuid;
1112

1213
/// Cbor encodable and decodable type trait.
1314
pub trait Cbor<'a> {

rust/vote-tx-v2/src/public_tx/prop_id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use minicbor::{Decode, Encode};
44

5-
use crate::gen_tx::Uuid;
5+
use crate::uuid::Uuid;
66

77
/// A public voting proposal id struct.
88
pub struct PropId(Uuid);

rust/vote-tx-v2/src/uuid.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! A CBOR encoded/decoded UUID struct.
2+
3+
use minicbor::{data::Tag, Decode, Decoder, Encode};
4+
5+
/// UUID CBOR tag <https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml/>.
6+
const UUID_TAG: u64 = 37;
7+
8+
/// A UUID struct, CBOR tag 37.
9+
#[derive(Debug, Clone, PartialEq)]
10+
pub struct Uuid(pub Vec<u8>);
11+
12+
impl Decode<'_, ()> for Uuid {
13+
fn decode(d: &mut Decoder<'_>, (): &mut ()) -> Result<Self, minicbor::decode::Error> {
14+
let tag = d.tag()?;
15+
if UUID_TAG != tag.as_u64() {
16+
return Err(minicbor::decode::Error::message(format!(
17+
"tag value must be: {UUID_TAG}, provided: {}",
18+
tag.as_u64(),
19+
)));
20+
}
21+
let choice = d.bytes()?.to_vec();
22+
Ok(Self(choice))
23+
}
24+
}
25+
26+
impl Encode<()> for Uuid {
27+
fn encode<W: minicbor::encode::Write>(
28+
&self, e: &mut minicbor::Encoder<W>, (): &mut (),
29+
) -> Result<(), minicbor::encode::Error<W::Error>> {
30+
e.tag(Tag::new(UUID_TAG))?;
31+
e.bytes(&self.0)?;
32+
Ok(())
33+
}
34+
}

0 commit comments

Comments
 (0)