From 965657d1b224a1c30363c909959ca6b8323a5b68 Mon Sep 17 00:00:00 2001 From: brent saner Date: Fri, 5 Sep 2025 18:55:01 -0400 Subject: [PATCH] v1.10.1 FIXED: * Missed a Reset on the inetcksum.InetChecksumSimple. --- netx/inetcksum/docs.go | 12 +++++++++--- netx/inetcksum/funcs_inetchecksumsimple.go | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/netx/inetcksum/docs.go b/netx/inetcksum/docs.go index fdeb497..7b8a738 100644 --- a/netx/inetcksum/docs.go +++ b/netx/inetcksum/docs.go @@ -13,11 +13,17 @@ It provides [InetChecksum], which can be used as a: * [io.Writer] * [io.WriterTo] -and is concurrency-safe. +and allows one to retrieve the actual bytes that were checksummed. +It is also fully concurrency-safe. There is also an [InetChecksumSimple] provided, which is more -tailored for performance/resource usage at the cost of concurrency -safety and data retention. +tailored for performance/resource usage at the cost of no concurrency +safety and no data retention, which can be used as a: + + * [hash.Hash] + * [io.ByteWriter] + * [io.StringWriter] + * [io.Writer] [RFC 1071]: https://datatracker.ietf.org/doc/html/rfc1071 [RFC 1141]: https://datatracker.ietf.org/doc/html/rfc1141 diff --git a/netx/inetcksum/funcs_inetchecksumsimple.go b/netx/inetcksum/funcs_inetchecksumsimple.go index 89624ef..1fdf712 100644 --- a/netx/inetcksum/funcs_inetchecksumsimple.go +++ b/netx/inetcksum/funcs_inetchecksumsimple.go @@ -22,6 +22,15 @@ func (i *InetChecksumSimple) BlockSize() (blockSize int) { return } +// Reset resets the state of an InetChecksumSimple. +func (i *InetChecksumSimple) Reset() { + + i.last = 0x00 + i.sum = 0 + i.last = 0x00 + +} + // Size returns how many bytes a checksum is. (It will always return 2.) func (i *InetChecksumSimple) Size() (bufSize int) { @@ -151,3 +160,13 @@ func (i *InetChecksumSimple) WriteByte(c byte) (err error) { return } + +// WriteString checksums a string. It conforms to [io.StringWriter]. +func (i *InetChecksumSimple) WriteString(s string) (n int, err error) { + + if n, err = i.Write([]byte(s)); err != nil { + return + } + + return +}