Debian Codegraph @

command/crypto/nacl/nacl.go

raw symbols SCIP
1 package nacl
2
3 import (
4 "encoding/base64"
5 "strings"
6
7 "github.com/pkg/errors"
8 "github.com/urfave/cli"
9 )
10
11 // Command returns the cli.Command for nacl and related subcommands.
12 func Command() cli.Command {
13 return cli.Command{
14 Name: "nacl",
15 Usage: "easy-to-use high-speed tools for encryption and signing",
16 UsageText: "step crypto nacl <subcommand> [arguments] [global-flags] [subcommand-flags]",
17 Description: `The **step crypto nacl** command group is a thin CLI wrapper around the NaCl
18 (pronounced "salt") cryptography library. NaCl's goal is to provide all of the
19 core operations needed to build higher-level cryptographic tools.
20
21 Perhaps its biggest advantage is simplicity. NaCl was designed to be easy to
22 use and hard to misuse. Typical cryptographic libraries force you to specify
23 choices for cryptographic primitives and constructions (e.g., sign this
24 message with 4096-bit RSA using PKCS#1 v2.0 with SHA-256). But most people are
25 not cryptographers. These choices become foot guns. By contrast, NaCl allows
26 you to simply say "sign this message". NaCl ships with a preselected choice --
27 a state-of-the-art signature system suitable for most applications -- and it
28 has a side mechanism through which a cryptographer can easily override the
29 choice of signature system.
30
31 There are language bindings and pure implementations of NaCl for all major
32 languages. For internal use cases where compatibility with open standards like
33 JWT are not an issue, NaCl should be your default choice for cryptographic
34 needs.
35
36 For more information on NaCl visit https://nacl.cr.yp.to`,
37 Subcommands: cli.Commands{
38 authCommand(),
39 boxCommand(),
40 secretboxCommand(),
41 signCommand(),
42 },
43 }
44 }
45
46 var b64Encoder = base64.RawURLEncoding
47
48 // decodeNonce returns the nonce in bytes. If the input has the prefix base64:
49 // it will decode the rest using the base64 standard encoding.
50 func decodeNonce(in string) ([]byte, error) {
51 nonce := []byte(in)
52 switch {
53 case strings.HasPrefix(in, "string:"):
54 return nonce[7:], nil
55 case strings.HasPrefix(in, "base64:"):
56 input := nonce[7:]
57 nonce = make([]byte, base64.StdEncoding.DecodedLen(len(input)))
58 n, err := base64.StdEncoding.Decode(nonce, input)
59 if err != nil {
60 return nil, errors.Wrap(err, "error decoding base64 nonce")
61 }
62 return nonce[:n], nil
63 default:
64 return nonce, nil
65 }
66 }