Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omnet/blob/main/om/codec/test/gen/tsoracle/main.go # omnet aien-dev/omnet Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omnet / om / codec / test / gen / tsoracle / main.go` 85 lines ยท 1950 bytes Raw Blame History 1 // SPDX-License-Identifier: Apache-2.0 2 // 3 // Cross-check referee for om/codec, never part of the implementation. It calls the real 4 // tailscale.com v1.102.0 tka.AUMHash and key.NodePublic text methods, so it needs the Go version 5 // that module requires (go >= 1.26.5). It reads driver case lines whose OP is aume, aumd, nkye or 6 // nkyd and prints results in the driver format. gen/check-tailscale.sh compares its output with 7 // gen/oracle, whose transcription of the same functions builds with go1.26.0. 8 package main 9 10 import ( 11 "bufio" 12 "encoding/hex" 13 "fmt" 14 "os" 15 "strings" 16 17 "go4.org/mem" 18 "tailscale.com/tka" 19 "tailscale.com/types/key" 20 ) 21 22 func fail(msg string) { 23 fmt.Fprintln(os.Stderr, "tsoracle:", msg) 24 os.Exit(2) 25 } 26 27 func hx(b []byte) string { 28 if len(b) == 0 { 29 return "-" 30 } 31 return hex.EncodeToString(b) 32 } 33 34 func main() { 35 in := bufio.NewScanner(os.Stdin) 36 in.Buffer(make([]byte, 1<<20), 1<<20) 37 out := bufio.NewWriter(os.Stdout) 38 defer out.Flush() 39 for in.Scan() { 40 f := strings.Split(in.Text(), " ") 41 if len(f) != 2 { 42 fail("bad line") 43 } 44 var a []byte 45 if f[1] != "-" { 46 var err error 47 if a, err = hex.DecodeString(f[1]); err != nil { 48 fail("bad hex") 49 } 50 } 51 switch f[0] { 52 case "aume": 53 var h tka.AUMHash 54 if copy(h[:], a) != 32 || len(a) != 32 { 55 fail("aume needs 32 bytes") 56 } 57 t, _ := h.MarshalText() 58 fmt.Fprintln(out, "ok "+string(t)) 59 case "nkye": 60 if len(a) != 32 { 61 fail("nkye needs 32 bytes") 62 } 63 k := key.NodePublicFromRaw32(mem.B(a)) 64 t, _ := k.MarshalText() 65 fmt.Fprintln(out, "ok "+string(t)) 66 case "aumd": 67 var h tka.AUMHash 68 if h.UnmarshalText(a) != nil { 69 fmt.Fprintln(out, "err") 70 continue 71 } 72 fmt.Fprintln(out, "ok "+hx(h[:])) 73 case "nkyd": 74 var k key.NodePublic 75 if k.UnmarshalText(a) != nil { 76 fmt.Fprintln(out, "err") 77 continue 78 } 79 r := k.Raw32() 80 fmt.Fprintln(out, "ok "+hx(r[:])) 81 default: 82 fail("unsupported op " + f[0]) 83 } 84 } 85 }