diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-11-21 21:50:21 -0800 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-11-21 21:50:21 -0800 |
| commit | fce31e6e8783cabf68111d9b2c60b00949846a51 (patch) | |
| tree | d562c572a1f157fa10d162e472accae96bf6ec3b | |
| parent | 8480223506c3242a8bdcea297062b5f67672c75f (diff) | |
| download | roseh.moe-fce31e6e8783cabf68111d9b2c60b00949846a51.tar.zst | |
Slightly simplify the int encoding
| -rw-r--r-- | roseh.moe.go | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/roseh.moe.go b/roseh.moe.go index a2e7ed2..687fe4c 100644 --- a/roseh.moe.go +++ b/roseh.moe.go @@ -338,14 +338,9 @@ func verify(msg, messageMAC []byte, purpose string) bool { } func marshalInt(x int64) []byte { - ux := uint64(x) << 1 - if x < 0 { - ux = ^ux - } buf := make([]byte, 8) - binary.BigEndian.PutUint64(buf, ux) - for len(buf) > 0 && buf[0] == 0 { - buf = buf[1:] + binary.BigEndian.PutUint64(buf, uint64(x)) + for ; len(buf) > 0 && buf[0] == 0; buf = buf[1:] { } return buf } @@ -356,15 +351,10 @@ func unmarshalInt(b []byte) (int64, bool) { } buf := make([]byte, 8) copy(buf[8-len(b):], b) - ux := binary.BigEndian.Uint64(buf) - x := int64(ux >> 1) - if ux&1 != 0 { - x = ^x - } - return x, true + return int64(binary.BigEndian.Uint64(buf)), true } -const yearOffset = 2089 +const yearOffset = 2025 func marshalTime(t time.Time) []byte { year, month, day := t.UTC().Date() |
