package magna import ( "fmt" ) // BufferOverflowError represents an error when there is a buffer overflow. type BufferOverflowError struct { Length int Offset int } func (e *BufferOverflowError) Error() string { return fmt.Sprintf("buffer overflow: attempted to read past buffer length %d at offset %d", e.Length, e.Offset) } func (e *BufferOverflowError) Is(target error) bool { _, ok := target.(*BufferOverflowError) return ok } // InvalidLabelError represents an error when an invalid label length is encountered. type InvalidLabelError struct { Length int } func (e *InvalidLabelError) Error() string { if e.Length > 63 { return fmt.Sprintf("invalid domain label: length %d exceeds maximum 63", e.Length) } if e.Length == 0 { return "invalid domain label: zero length label encountered" } // XXX: this should be unreachable return fmt.Sprintf("invalid domain label: unexpected length %d", e.Length) } func (e *InvalidLabelError) Is(target error) bool { _, ok := target.(*InvalidLabelError) return ok } // DomainCompressionError represents an error related to domain compression. type DomainCompressionError struct{} func (e *DomainCompressionError) Error() string { return "invalid domain compression: pointer loop detected" } func (e *DomainCompressionError) Is(target error) bool { _, ok := target.(*DomainCompressionError) return ok }