Skip to content

Commit

Permalink
Merge #173: Make a couple of the functions on CheckedHrpstring stru…
Browse files Browse the repository at this point in the history
…ct public

bde1df5 Make validate_witness_program_length public (Tobin C. Harding)
bdd6855 Make validate_padding public (Tobin C. Harding)

Pull request description:

  These two functions are useful to users of the lib, lets make them public.

ACKs for top commit:
  apoelstra:
    ACK bde1df5

Tree-SHA512: dc59f120a9cee1ae00007e14901feae3127e54d0f9d6f34204fc0909d890a84a3c9357066600f0ca203e21b91825365d32284e5acabde3f662aae25f772e7194
  • Loading branch information
apoelstra committed Jan 23, 2024
2 parents de97a8e + bde1df5 commit e6660be
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/primitives/decode.rs
Expand Up @@ -397,7 +397,7 @@ impl<'s> CheckedHrpstring<'s> {
let witness_version = Fe32::from_char(self.ascii[0].into()).unwrap();
self.ascii = &self.ascii[1..]; // Remove the witness version byte.

self.validate_padding()?;
self.validate_segwit_padding()?;
self.validate_witness_program_length(witness_version)?;

Ok(SegwitHrpstring { hrp: self.hrp(), witness_version, ascii: self.ascii })
Expand All @@ -410,7 +410,8 @@ impl<'s> CheckedHrpstring<'s> {
/// From BIP-173:
/// > Re-arrange those bits into groups of 8 bits. Any incomplete group at the
/// > end MUST be 4 bits or less, MUST be all zeroes, and is discarded.
fn validate_padding(&self) -> Result<(), PaddingError> {
#[inline]
pub fn validate_segwit_padding(&self) -> Result<(), PaddingError> {
if self.ascii.is_empty() {
return Ok(()); // Empty data implies correct padding.
}
Expand Down Expand Up @@ -443,7 +444,8 @@ impl<'s> CheckedHrpstring<'s> {
/// Validates the segwit witness length rules.
///
/// Must be called after the witness version byte is removed from the data part.
fn validate_witness_program_length(
#[inline]
pub fn validate_witness_program_length(
&self,
witness_version: Fe32,
) -> Result<(), WitnessLengthError> {
Expand Down

0 comments on commit e6660be

Please sign in to comment.