mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-04-08 11:58:17 +02:00
add size validation to nip19 decoder.
This commit is contained in:
parent
63614bb152
commit
b8eeb658cc
@ -44,6 +44,9 @@ func Decode(bech32string string) (prefix string, value any, err error) {
|
||||
|
||||
switch t {
|
||||
case TLVDefault:
|
||||
if len(v) < 32 {
|
||||
return prefix, nil, fmt.Errorf("pubkey is less than 32 bytes (%d)", len(v))
|
||||
}
|
||||
result.PublicKey = hex.EncodeToString(v)
|
||||
case TLVRelay:
|
||||
result.Relays = append(result.Relays, string(v))
|
||||
@ -69,10 +72,16 @@ func Decode(bech32string string) (prefix string, value any, err error) {
|
||||
|
||||
switch t {
|
||||
case TLVDefault:
|
||||
if len(v) < 32 {
|
||||
return prefix, nil, fmt.Errorf("id is less than 32 bytes (%d)", len(v))
|
||||
}
|
||||
result.ID = hex.EncodeToString(v)
|
||||
case TLVRelay:
|
||||
result.Relays = append(result.Relays, string(v))
|
||||
case TLVAuthor:
|
||||
if len(v) < 32 {
|
||||
return prefix, nil, fmt.Errorf("author is less than 32 bytes (%d)", len(v))
|
||||
}
|
||||
result.Author = hex.EncodeToString(v)
|
||||
case TLVKind:
|
||||
result.Kind = int(binary.BigEndian.Uint32(v))
|
||||
@ -102,6 +111,9 @@ func Decode(bech32string string) (prefix string, value any, err error) {
|
||||
case TLVRelay:
|
||||
result.Relays = append(result.Relays, string(v))
|
||||
case TLVAuthor:
|
||||
if len(v) < 32 {
|
||||
return prefix, nil, fmt.Errorf("author is less than 32 bytes (%d)", len(v))
|
||||
}
|
||||
result.PublicKey = hex.EncodeToString(v)
|
||||
case TLVKind:
|
||||
result.Kind = int(binary.BigEndian.Uint32(v))
|
||||
|
Loading…
x
Reference in New Issue
Block a user