aboutsummaryrefslogtreecommitdiff
path: root/cryptobyte/string.go
diff options
context:
space:
mode:
authorhopehook <hopehook.com@gmail.com>2022-08-03 13:31:10 +0800
committerGopher Robot <gobot@golang.org>2022-08-24 17:17:10 +0000
commit5757bc0c5503e9832a646fcf49ea46445f253091 (patch)
tree6989e241a7a314ad92cf5683f5973230b4d34ab1 /cryptobyte/string.go
parentbc19a97f63c84bfb02ed9bb14fb0f8f6bec9a964 (diff)
downloadgo-x-crypto-5757bc0c5503e9832a646fcf49ea46445f253091.tar.xz
cryptobyte: add ReadUint64 and AddUint64
Fixes golang/go#53481. Change-Id: Ic00eef498d1d3b5b0ca5c9c526fac7c26de30cf2 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/421014 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Filippo Valsorda <filippo@golang.org> Run-TryBot: hopehook <hopehook@qq.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Roland Shoemaker <roland@golang.org>
Diffstat (limited to 'cryptobyte/string.go')
-rw-r--r--cryptobyte/string.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/cryptobyte/string.go b/cryptobyte/string.go
index 589d297..0531a3d 100644
--- a/cryptobyte/string.go
+++ b/cryptobyte/string.go
@@ -81,6 +81,17 @@ func (s *String) ReadUint32(out *uint32) bool {
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 {
+ v := s.read(8)
+ if v == nil {
+ return false
+ }
+ *out = uint64(v[0])<<56 | uint64(v[1])<<48 | uint64(v[2])<<40 | uint64(v[3])<<32 | uint64(v[4])<<24 | uint64(v[5])<<16 | uint64(v[6])<<8 | uint64(v[7])
+ return true
+}
+
func (s *String) readUnsigned(out *uint32, length int) bool {
v := s.read(length)
if v == nil {