this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue/pkg/crypto: make return types bytes, instead of list

Note that the generated builtins indicate a bytes
or string return type. This is fine, as the actual
conversion will restrict it to bytes.

Closes #92

Change-Id: Ib8a92d9feebf6f298dc0c35d2831f80e5d7a76ca
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3048
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>

authored by

Marcel van Lohuizen and committed by
Marcel van Lohuizen
330999be 5e8c3916

+75 -40
+27
cue/builtin_test.go
··· 57 57 test("math", `math.Floor("foo")`), 58 58 `_|_(cannot use "foo" (type string) as number in argument 1 to math.Floor)`, 59 59 }, { 60 + test("crypto/sha256", `sha256.Sum256("hash me")`), 61 + `'\xeb \x1a\xf5\xaa\xf0\xd6\x06)\xd3Ҧ\x1eFl\xfc\x0f\xed\xb5\x17\xad\xd81\xec\xacR5\xe1کc\xd6'`, 62 + }, { 63 + test("crypto/md5", `len(md5.Sum("hash me"))`), 64 + `16`, 65 + }, { 66 + test("crypto/sha1", `len(sha1.Sum("hash me"))`), 67 + `20`, 68 + }, { 69 + test("crypto/sha256", `len(sha256.Sum256("hash me"))`), 70 + `32`, 71 + }, { 72 + test("crypto/sha256", `len(sha256.Sum224("hash me"))`), 73 + `28`, 74 + }, { 75 + test("crypto/sha512", `len(sha512.Sum512("hash me"))`), 76 + `64`, 77 + }, { 78 + test("crypto/sha512", `len(sha512.Sum384("hash me"))`), 79 + `48`, 80 + }, { 81 + test("crypto/sha512", `len(sha512.Sum512_224("hash me"))`), 82 + `28`, 83 + }, { 84 + test("crypto/sha512", `len(sha512.Sum512_256("hash me"))`), 85 + `32`, 86 + }, { 60 87 test("encoding/base64", `base64.Encode(null, "foo")`), 61 88 `"Zm9v"`, 62 89 }, {
+24 -16
cue/builtins.go
··· 143 143 }, { 144 144 Name: "Sum", 145 145 Params: []kind{bytesKind | stringKind}, 146 - Result: topKind, 146 + Result: bytesKind | stringKind, 147 147 Func: func(c *callCtxt) { 148 148 data := c.bytes(0) 149 149 c.ret = func() interface{} { 150 - return md5.Sum(data) 150 + a := md5.Sum(data) 151 + return a[:] 151 152 }() 152 153 }, 153 154 }}, ··· 162 163 }, { 163 164 Name: "Sum", 164 165 Params: []kind{bytesKind | stringKind}, 165 - Result: topKind, 166 + Result: bytesKind | stringKind, 166 167 Func: func(c *callCtxt) { 167 168 data := c.bytes(0) 168 169 c.ret = func() interface{} { 169 - return sha1.Sum(data) 170 + a := sha1.Sum(data) 171 + return a[:] 170 172 }() 171 173 }, 172 174 }}, ··· 184 186 }, { 185 187 Name: "Sum256", 186 188 Params: []kind{bytesKind | stringKind}, 187 - Result: topKind, 189 + Result: bytesKind | stringKind, 188 190 Func: func(c *callCtxt) { 189 191 data := c.bytes(0) 190 192 c.ret = func() interface{} { 191 - return sha256.Sum256(data) 193 + a := sha256.Sum256(data) 194 + return a[:] 192 195 }() 193 196 }, 194 197 }, { 195 198 Name: "Sum224", 196 199 Params: []kind{bytesKind | stringKind}, 197 - Result: topKind, 200 + Result: bytesKind | stringKind, 198 201 Func: func(c *callCtxt) { 199 202 data := c.bytes(0) 200 203 c.ret = func() interface{} { 201 - return sha256.Sum224(data) 204 + a := sha256.Sum224(data) 205 + return a[:] 202 206 }() 203 207 }, 204 208 }}, ··· 222 226 }, { 223 227 Name: "Sum512", 224 228 Params: []kind{bytesKind | stringKind}, 225 - Result: topKind, 229 + Result: bytesKind | stringKind, 226 230 Func: func(c *callCtxt) { 227 231 data := c.bytes(0) 228 232 c.ret = func() interface{} { 229 - return sha512.Sum512(data) 233 + a := sha512.Sum512(data) 234 + return a[:] 230 235 }() 231 236 }, 232 237 }, { 233 238 Name: "Sum384", 234 239 Params: []kind{bytesKind | stringKind}, 235 - Result: topKind, 240 + Result: bytesKind | stringKind, 236 241 Func: func(c *callCtxt) { 237 242 data := c.bytes(0) 238 243 c.ret = func() interface{} { 239 - return sha512.Sum384(data) 244 + a := sha512.Sum384(data) 245 + return a[:] 240 246 }() 241 247 }, 242 248 }, { 243 249 Name: "Sum512_224", 244 250 Params: []kind{bytesKind | stringKind}, 245 - Result: topKind, 251 + Result: bytesKind | stringKind, 246 252 Func: func(c *callCtxt) { 247 253 data := c.bytes(0) 248 254 c.ret = func() interface{} { 249 - return sha512.Sum512_224(data) 255 + a := sha512.Sum512_224(data) 256 + return a[:] 250 257 }() 251 258 }, 252 259 }, { 253 260 Name: "Sum512_256", 254 261 Params: []kind{bytesKind | stringKind}, 255 - Result: topKind, 262 + Result: bytesKind | stringKind, 256 263 Func: func(c *callCtxt) { 257 264 data := c.bytes(0) 258 265 c.ret = func() interface{} { 259 - return sha512.Sum512_256(data) 266 + a := sha512.Sum512_256(data) 267 + return a[:] 260 268 }() 261 269 }, 262 270 }},
+3 -4
pkg/crypto/md5/md5.go
··· 16 16 // Use of this source code is governed by a BSD-style 17 17 // license that can be found in the LICENSE file. 18 18 19 - //go:generate qgo extract crypto/md5 20 - 21 19 package md5 22 20 23 21 import "crypto/md5" ··· 29 27 const BlockSize = 64 30 28 31 29 // Sum returns the MD5 checksum of the data. 32 - func Sum(data []byte) [Size]byte { 33 - return md5.Sum(data) 30 + func Sum(data []byte) []byte { 31 + a := md5.Sum(data) 32 + return a[:] 34 33 }
+3 -4
pkg/crypto/sha1/sha1.go
··· 16 16 // Use of this source code is governed by a BSD-style 17 17 // license that can be found in the LICENSE file. 18 18 19 - //go:generate qgo extract crypto/sha1 20 - 21 19 package sha1 22 20 23 21 import "crypto/sha1" ··· 29 27 const BlockSize = 64 30 28 31 29 // Sum returns the SHA-1 checksum of the data. 32 - func Sum(data []byte) [Size]byte { 33 - return sha1.Sum(data) 30 + func Sum(data []byte) []byte { 31 + a := sha1.Sum(data) 32 + return a[:] 34 33 }
+6 -6
pkg/crypto/sha256/sha256.go
··· 16 16 // Use of this source code is governed by a BSD-style 17 17 // license that can be found in the LICENSE file. 18 18 19 - //go:generate qgo extract crypto/sha256 20 - 21 19 package sha256 22 20 23 21 import "crypto/sha256" ··· 32 30 const BlockSize = 64 33 31 34 32 // Sum256 returns the SHA256 checksum of the data. 35 - func Sum256(data []byte) [Size]byte { 36 - return sha256.Sum256(data) 33 + func Sum256(data []byte) []byte { 34 + a := sha256.Sum256(data) 35 + return a[:] 37 36 } 38 37 39 38 // Sum224 returns the SHA224 checksum of the data. 40 - func Sum224(data []byte) (sum224 [Size224]byte) { 41 - return sha256.Sum224(data) 39 + func Sum224(data []byte) (sum224 []byte) { 40 + a := sha256.Sum224(data) 41 + return a[:] 42 42 }
+12 -10
pkg/crypto/sha512/sha512.go
··· 16 16 // Use of this source code is governed by a BSD-style 17 17 // license that can be found in the LICENSE file. 18 18 19 - //go:generate qgo extract crypto/sha512 20 - 21 19 package sha512 22 20 23 21 import "crypto/sha512" ··· 41 39 ) 42 40 43 41 // Sum512 returns the SHA512 checksum of the data. 44 - func Sum512(data []byte) [Size]byte { 45 - return sha512.Sum512(data) 42 + func Sum512(data []byte) []byte { 43 + a := sha512.Sum512(data) 44 + return a[:] 46 45 } 47 46 48 47 // Sum384 returns the SHA384 checksum of the data. 49 - func Sum384(data []byte) (sum384 [Size384]byte) { 50 - return sha512.Sum384(data) 48 + func Sum384(data []byte) (sum384 []byte) { 49 + a := sha512.Sum384(data) 50 + return a[:] 51 51 } 52 52 53 53 // Sum512_224 returns the Sum512/224 checksum of the data. 54 - func Sum512_224(data []byte) (sum224 [Size224]byte) { 55 - return sha512.Sum512_224(data) 54 + func Sum512_224(data []byte) (sum224 []byte) { 55 + a := sha512.Sum512_224(data) 56 + return a[:] 56 57 } 57 58 58 59 // Sum512_256 returns the Sum512/256 checksum of the data. 59 - func Sum512_256(data []byte) (sum256 [Size256]byte) { 60 - return sha512.Sum512_256(data) 60 + func Sum512_256(data []byte) (sum256 []byte) { 61 + a := sha512.Sum512_256(data) 62 + return a[:] 61 63 }