MCPcopy
hub / github.com/pyca/cryptography / validateVectors

Function validateVectors

docs/development/custom-vectors/arc4/verify_arc4.go:62–106  ·  view source on GitHub ↗
(verifier vectorVerifier, filename string)

Source from the content-addressed store, hash-verified

60}
61
62func validateVectors(verifier vectorVerifier, filename string) {
63 vectors, err := os.Open(filename)
64 if err != nil {
65 panic(err)
66 }
67 defer vectors.Close()
68
69 var segments []string
70 var vector *vectorArgs
71
72 scanner := bufio.NewScanner(vectors)
73 for scanner.Scan() {
74 segments = strings.Split(scanner.Text(), " = ")
75
76 switch {
77 case strings.ToUpper(segments[0]) == "COUNT":
78 if vector != nil {
79 verifier.validate(vector.count,
80 vector.offset,
81 unhexlify(vector.key),
82 unhexlify(vector.plaintext),
83 unhexlify(vector.ciphertext))
84 }
85 vector = &vectorArgs{count: segments[1]}
86 case strings.ToUpper(segments[0]) == "OFFSET":
87 vector.offset, err = strconv.ParseUint(segments[1], 10, 64)
88 if err != nil {
89 panic(err)
90 }
91 case strings.ToUpper(segments[0]) == "KEY":
92 vector.key = segments[1]
93 case strings.ToUpper(segments[0]) == "PLAINTEXT":
94 vector.plaintext = segments[1]
95 case strings.ToUpper(segments[0]) == "CIPHERTEXT":
96 vector.ciphertext = segments[1]
97 }
98 }
99 if vector != nil {
100 verifier.validate(vector.count,
101 vector.offset,
102 unhexlify(vector.key),
103 unhexlify(vector.plaintext),
104 unhexlify(vector.ciphertext))
105 }
106}
107
108func main() {
109 validateVectors(arc4Verifier{}, "vectors/cryptography_vectors/ciphers/ARC4/arc4.txt")

Callers 1

mainFunction · 0.70

Calls 2

unhexlifyFunction · 0.70
validateMethod · 0.65

Tested by

no test coverage detected