diff options
| author | Daniel Mangum <georgedanielmangum@gmail.com> | 2023-09-06 19:20:46 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-09-07 16:27:37 +0000 |
| commit | e90f1e17ee2ffe351a8295e8ae8b66afda2969c6 (patch) | |
| tree | 64eddcb4e2a4b2f1f269ad4b153ce938ae09e502 /cryptobyte/string.go | |
| parent | d359caa4a39d59a440003b37a6cc7ace3871fd4a (diff) | |
| download | go-x-crypto-e90f1e17ee2ffe351a8295e8ae8b66afda2969c6.tar.xz | |
cryptobyte: add uint48 methods
Adds uint48 methods for cryptobyte.Builder and cryptobyte.String.
Supporting 48-bit unsigned integers is useful for working with protocols
that use them for sequence numbers, such as DTLS.
Fixes golang/go#61275
Change-Id: Ibe49422d37644b9212b28b123dc5e01850f7b05b
GitHub-Last-Rev: 11b388c240109c8f4ac23880645c901ce6d2f093
GitHub-Pull-Request: golang/crypto#265
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/508675
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: qiulaidongfeng <2645477756@qq.com>
Run-TryBot: Roland Shoemaker <roland@golang.org>
Auto-Submit: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'cryptobyte/string.go')
| -rw-r--r-- | cryptobyte/string.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/cryptobyte/string.go b/cryptobyte/string.go index 0531a3d..10692a8 100644 --- a/cryptobyte/string.go +++ b/cryptobyte/string.go @@ -81,6 +81,17 @@ func (s *String) ReadUint32(out *uint32) bool { return true } +// ReadUint48 decodes a big-endian, 48-bit value into out and advances over it. +// It reports whether the read was successful. +func (s *String) ReadUint48(out *uint64) bool { + v := s.read(6) + if v == nil { + return false + } + *out = uint64(v[0])<<40 | uint64(v[1])<<32 | uint64(v[2])<<24 | uint64(v[3])<<16 | uint64(v[4])<<8 | uint64(v[5]) + return true +} + // ReadUint64 decodes a big-endian, 64-bit value into out and advances over it. // It reports whether the read was successful. func (s *String) ReadUint64(out *uint64) bool { |
