MCPcopy Index your code
hub / github.com/smallstep/cli / boxOpenAction

Function boxOpenAction

command/crypto/nacl/box.go:236–300  ·  view source on GitHub ↗
(ctx *cli.Context)

Source from the content-addressed store, hash-verified

234}
235
236func boxOpenAction(ctx *cli.Context) error {
237 if err := errs.NumberOfArguments(ctx, 3); err != nil {
238 return err
239 }
240
241 args := ctx.Args()
242 nonce, err := decodeNonce(args[0])
243 if err != nil {
244 return err
245 }
246 pubFile, privFile := args[1], args[2]
247
248 if len(nonce) > 24 {
249 return errors.New("nonce cannot be longer than 24 bytes")
250 }
251
252 pub, err := os.ReadFile(pubFile)
253 if err != nil {
254 return errs.FileError(err, pubFile)
255 } else if len(pub) != 32 {
256 return errors.New("invalid public key: key size is not 32 bytes")
257 }
258
259 priv, err := os.ReadFile(privFile)
260 if err != nil {
261 return errs.FileError(err, privFile)
262 } else if len(priv) != 32 {
263 return errors.New("invalid private key: key size is not 32 bytes")
264 }
265
266 input, err := utils.ReadAll(os.Stdin)
267 if err != nil {
268 return errs.Wrap(err, "error reading input")
269 }
270
271 var rawInput []byte
272 if ctx.Bool("raw") {
273 rawInput = input
274 } else {
275 // DecodeLen returns the maximum length,
276 // Decode will return the actual length.
277 rawInput = make([]byte, b64Encoder.DecodedLen(len(input)))
278 n, err := b64Encoder.Decode(rawInput, input)
279 if err != nil {
280 return errors.Wrap(err, "error decoding base64 input")
281 }
282 rawInput = rawInput[:n]
283 }
284
285 var n [24]byte
286 var pb, pv [32]byte
287 copy(n[:], nonce)
288 copy(pb[:], pub)
289 copy(pv[:], priv)
290
291 // Fixme: if we prepend the nonce in the seal we can use rawInput[24:]
292 // as the message and rawInput[:24] as the nonce instead of requiring one.
293 raw, ok := box.Open(nil, rawInput, &n, &pb, &pv)

Callers

nothing calls this directly

Calls 2

ReadAllFunction · 0.92
decodeNonceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…