MCPcopy
hub / github.com/smallstep/cli / createAction

Function createAction

command/crypto/keypair.go:97–204  ·  view source on GitHub ↗
(ctx *cli.Context)

Source from the content-addressed store, hash-verified

95}
96
97func createAction(ctx *cli.Context) (err error) {
98 if err := errs.NumberOfArguments(ctx, 2); err != nil {
99 return err
100 }
101
102 pubFile := ctx.Args().Get(0)
103 privFile := ctx.Args().Get(1)
104 if pubFile == privFile {
105 return errs.EqualArguments(ctx, "PUB_FILE", "PRIV_FILE")
106 }
107
108 insecureMode := ctx.Bool("insecure")
109 noPass := ctx.Bool("no-password")
110 passwordFile := ctx.String("password-file")
111 if noPass && passwordFile != "" {
112 return errs.IncompatibleFlag(ctx, "no-password", "password-file")
113 }
114 if noPass && !insecureMode {
115 return errs.RequiredWithFlag(ctx, "no-password", "insecure")
116 }
117
118 // Read password if necessary
119 var password string
120 if passwordFile != "" {
121 password, err = utils.ReadStringPasswordFromFile(passwordFile)
122 if err != nil {
123 return err
124 }
125 }
126
127 var pub, priv interface{}
128 fromJWK := ctx.String("from-jwk")
129 if fromJWK != "" {
130 switch {
131 case ctx.IsSet("kty"):
132 return errs.IncompatibleFlagWithFlag(ctx, "from-jwk", "kty")
133 case ctx.IsSet("curve"):
134 return errs.IncompatibleFlagWithFlag(ctx, "from-jwk", "curve")
135 case ctx.IsSet("size"):
136 return errs.IncompatibleFlagWithFlag(ctx, "from-jwk", "size")
137 }
138
139 var jwk *jose.JSONWebKey
140 jwk, err = jose.ReadKey(fromJWK)
141 if err != nil {
142 return err
143 }
144
145 if jwk.IsPublic() {
146 pub = jwk.Key
147 } else {
148 pub = jwk.Public().Key
149 priv = jwk.Key
150 }
151 } else {
152 var (
153 kty, crv string
154 size int

Callers

nothing calls this directly

Calls 4

GetKeyDetailsFromCLIFunction · 0.92
StringMethod · 0.65
PublicMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…