Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 29ba275293 |
+20
-3
@@ -26,15 +26,15 @@ func Validate(e Event) error {
|
|||||||
// ValidateStructure checks that all event fields conform to the protocol
|
// ValidateStructure checks that all event fields conform to the protocol
|
||||||
// specification: hex lengths, tag structure, and field formats.
|
// specification: hex lengths, tag structure, and field formats.
|
||||||
func ValidateStructure(e Event) error {
|
func ValidateStructure(e Event) error {
|
||||||
if !isLowerHex(e.PubKey, 64) {
|
if !IsValidKey(e.PubKey) {
|
||||||
return errors.MalformedPubKey
|
return errors.MalformedPubKey
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isLowerHex(e.ID, 64) {
|
if !IsValidID(e.ID) {
|
||||||
return errors.MalformedID
|
return errors.MalformedID
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isLowerHex(e.Sig, 128) {
|
if !IsValidSig(e.Sig) {
|
||||||
return errors.MalformedSig
|
return errors.MalformedSig
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +63,23 @@ func ValidateSignature(e Event) error {
|
|||||||
return validateSignatureBytes(idBytes, e.Sig, e.PubKey)
|
return validateSignatureBytes(idBytes, e.Sig, e.PubKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Value validators
|
||||||
|
|
||||||
|
// IsValidKey verifies that a public or private key is properly formatted.
|
||||||
|
func IsValidKey(value string) bool {
|
||||||
|
return isLowerHex(value, 64)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValidKey verifies that an event id is properly formatted.
|
||||||
|
func IsValidID(value string) bool {
|
||||||
|
return isLowerHex(value, 64)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValidKey verifies that an event signature is properly formatted.
|
||||||
|
func IsValidSig(value string) bool {
|
||||||
|
return isLowerHex(value, 128)
|
||||||
|
}
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
|
|
||||||
func checkIDMatch(e Event) ([]byte, error) {
|
func checkIDMatch(e Event) ([]byte, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user