Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DecodeNoLimitGeneric to bech32.go #2186

Merged
merged 1 commit into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions btcutil/bech32/bech32.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,14 @@ func bech32VerifyChecksum(hrp string, data []byte) (Version, bool) {
return VersionUnknown, false
}

// DecodeNoLimit is a bech32 checksum version aware arbitrary string length
// decoder. This function will return the version of the decoded checksum
// constant so higher level validation can be performed to ensure the correct
// version of bech32 was used when encoding.
func decodeNoLimit(bech string) (string, []byte, Version, error) {
// DecodeNoLimitWithVersion is a bech32 checksum version aware arbitrary string
// length decoder. This function will return the version of the decoded
// checksum constant so higher level validation can be performed to ensure the
// correct version of bech32 was used when encoding.
//
// Note that the returned data is 5-bit (base32) encoded and the human-readable
// part will be lowercase.
func DecodeNoLimitWithVersion(bech string) (string, []byte, Version, error) {
// The minimum allowed size of a bech32 string is 8 characters, since it
// needs a non-empty HRP, a separator, and a 6 character checksum.
if len(bech) < 8 {
Expand Down Expand Up @@ -262,7 +265,7 @@ func decodeNoLimit(bech string) (string, []byte, Version, error) {
// Note that the returned data is 5-bit (base32) encoded and the human-readable
// part will be lowercase.
func DecodeNoLimit(bech string) (string, []byte, error) {
hrp, data, _, err := decodeNoLimit(bech)
hrp, data, _, err := DecodeNoLimitWithVersion(bech)
return hrp, data, err
}

Expand All @@ -277,7 +280,7 @@ func Decode(bech string) (string, []byte, error) {
return "", nil, ErrInvalidLength(len(bech))
}

hrp, data, _, err := decodeNoLimit(bech)
hrp, data, _, err := DecodeNoLimitWithVersion(bech)
return hrp, data, err
}

Expand All @@ -291,7 +294,7 @@ func DecodeGeneric(bech string) (string, []byte, Version, error) {
return "", nil, VersionUnknown, ErrInvalidLength(len(bech))
}

return decodeNoLimit(bech)
return DecodeNoLimitWithVersion(bech)
}

// encodeGeneric is the base bech32 encoding function that is aware of the
Expand Down
Loading