Skip to content

Commit 8eb0c4b

Browse files
committed
Move FromBase32 trait into de module
1 parent 3d8f887 commit 8eb0c4b

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

fuzz/src/bolt11_deser.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
3838

3939
// Our data serialization is loss-less
4040
assert_eq!(
41-
RawDataPart::from_base32(&invoice_data_base32)
42-
.expect("faild parsing out own encoding"),
41+
RawDataPart::from_base32(&invoice_data_base32).expect("faild parsing out own encoding"),
4342
invoice_data
4443
);
4544

lightning-invoice/src/de.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,19 @@ use bitcoin::secp256k1::PublicKey;
2323

2424
use super::{Bolt11Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiryDelta, Fallback, PayeePubKey, Bolt11InvoiceSignature, PositiveTimestamp,
2525
Bolt11SemanticError, PrivateRoute, Bolt11ParseError, ParseOrSemanticError, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawBolt11Invoice,
26-
constants, SignedRawBolt11Invoice, RawDataPart, Bolt11InvoiceFeatures, FromBase32};
26+
constants, SignedRawBolt11Invoice, RawDataPart, Bolt11InvoiceFeatures};
2727

2828
use self::hrp_sm::parse_hrp;
2929

30+
/// Trait for paring/converting base32 slice.
31+
pub trait FromBase32: Sized {
32+
/// The associated error which can be returned from parsing (e.g. because of bad padding).
33+
type Err;
34+
35+
/// Convert a base32 slice to `Self`.
36+
fn from_base32(b32: &[Fe32]) -> Result<Self, Self::Err>;
37+
}
38+
3039
// FromBase32 implementations are here, because the trait is in this module.
3140

3241
impl FromBase32 for Vec<u8> {

lightning-invoice/src/lib.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,8 @@ use crate::prelude::*;
8080
/// Re-export serialization traits
8181
#[cfg(fuzzing)]
8282
pub use crate::ser::Base32Iterable;
83-
84-
/// Trait for paring/converting base32 slice.
85-
pub trait FromBase32: Sized {
86-
/// The associated error which can be returned from parsing (e.g. because of bad padding).
87-
type Err;
88-
89-
/// Convert a base32 slice to `Self`.
90-
fn from_base32(b32: &[Fe32]) -> Result<Self, Self::Err>;
91-
}
83+
#[cfg(fuzzing)]
84+
pub use crate::de::FromBase32;
9285

9386
/// Errors that indicate what is wrong with the invoice. They have some granularity for debug
9487
/// reasons, but should generally result in an "invalid BOLT11 invoice" message for the user.
@@ -1000,6 +993,8 @@ macro_rules! find_all_extract {
1000993
impl RawBolt11Invoice {
1001994
/// Hash the HRP as bytes and signatureless data part.
1002995
fn hash_from_parts(hrp_bytes: &[u8], data_without_signature: &[Fe32]) -> [u8; 32] {
996+
use crate::de::FromBase32;
997+
1003998
let mut preimage = Vec::<u8>::from(hrp_bytes);
1004999

10051000
let mut data_part = Vec::from(data_without_signature);

lightning-invoice/src/test_ser_de.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
use crate::de::FromBase32;
12
use crate::ser::{Base32Iterable, Base32Len};
2-
use crate::{
3-
sha256, FromBase32, PayeePubKey, PaymentSecret, PositiveTimestamp, RawDataPart, Sha256,
4-
};
3+
use crate::{sha256, PayeePubKey, PaymentSecret, PositiveTimestamp, RawDataPart, Sha256};
54
use bech32::Fe32;
65
use core::fmt::Debug;
76
use std::str::FromStr;

0 commit comments

Comments
 (0)