func (j JWKTest) checkPubPriv(t *testing.T, m map[string]interface{}) {
	checkSize := func(v string, defaultSize int) {
		bytes, err := base64.RawURLEncoding.DecodeString(v)
		assert.FatalError(t, err)
		if v, ok := j.command.flags["size"]; ok {
			size, err := strconv.Atoi(v)
			assert.FatalError(t, err)
			assert.Equals(t, len(bytes)*8, size)
		} else {
			assert.Equals(t, len(bytes)*8, defaultSize)
		}
	}
	checkSizeBytes := func(v string, defaultSize int) {
		bytes, err := base64.RawURLEncoding.DecodeString(v)
		assert.FatalError(t, err)
		if v, ok := j.command.flags["size"]; ok {
			size, err := strconv.Atoi(v)
			assert.FatalError(t, err)
			assert.Equals(t, len(bytes), size)
		} else {
			assert.Equals(t, len(bytes), defaultSize)
		}
	}
	kty := j.kty()
	assert.Equals(t, kty, m["kty"])
	if v, ok := j.command.flags["use"]; ok {
		assert.Equals(t, v, m["use"])
	} else {
		assert.Equals(t, "sig", m["use"])
	}
	if v, ok := j.command.flags["kid"]; ok {
		assert.Equals(t, v, m["kid"])
	} else {
		assert.False(t, "" == m["kid"])
	}
	if kty == "EC" {
		_, ok := m["size"]
		assert.True(t, !ok, "size attribute for EC key")
		if v, ok := j.command.flags["crv"]; ok {
			assert.Equals(t, v, m["crv"])
		} else {
			switch j.command.flags["alg"] {
			case "ES256":
				assert.Equals(t, "P-256", m["crv"])
			case "ES384":
				assert.Equals(t, "P-384", m["crv"])
			case "ES512":
				assert.Equals(t, "P-521", m["crv"])
			default:
				assert.Equals(t, "P-256", m["crv"])
			}
		}
		if v, ok := j.command.flags["alg"]; ok {
			assert.Equals(t, v, m["alg"])
		} else {
			if m["use"] == "enc" {
				assert.Equals(t, "ECDH-ES", m["alg"])
			} else {
				switch m["crv"] {
				case "P-256":
					assert.Equals(t, "ES256", m["alg"])
				case "P-384":
					assert.Equals(t, "ES384", m["alg"])
				case "P-521":
					assert.Equals(t, "ES512", m["alg"])
				}
			}
		}
	} else if kty == "OKP" {
		_, ok := m["size"]
		assert.True(t, !ok, "size attribute for OKP key")
		assert.Equals(t, "Ed25519", m["crv"])
		assert.Equals(t, "EdDSA", m["alg"])
		_, ok = m["x"]
		assert.True(t, ok, "JWK with \"kty\" of \"OKP\" should have \"x\" parameter (public key)")
	} else if kty == "RSA" {
		_, ok := m["crv"]
		assert.True(t, !ok, "crv attribute for non-EC key")
		if v, ok := j.command.flags["alg"]; ok {
			assert.Equals(t, v, m["alg"])
		} else {
			assert.Equals(t, "RS256", m["alg"])
		}
		n, ok := m["n"]
		assert.True(t, ok, "JWK with \"kty\" of \"RSA\" should have \"n\" parameter (modulus)")
		_, ok = m["e"]
		assert.True(t, ok, "JWK with \"kty\" of \"RSA\" should have \"e\" parameter (exponent)")
		checkSize(n.(string), 2048)
	} else if kty == "oct" {
		_, ok := m["crv"]
		assert.True(t, !ok, "crv attribute for non-EC key")
		if v, ok := j.command.flags["alg"]; ok {
			assert.Equals(t, v, m["alg"])
		} else {
			assert.Equals(t, "HS256", m["alg"])
		}
		k, ok := m["k"]
		assert.True(t, ok, "JWK with \"kty\" of \"oct\" should have \"k\" paramater (key)")
		checkSizeBytes(k.(string), 32)
	} else {
		assert.True(t, false, fmt.Sprintf("invalid key type: %s", kty))
	}
}
/*
func (j JWKTest) crv() string {
if v, ok := j.command.flags["crv"]; ok {
return v, true
} else if v, ok = j.command.flags["curve"]; ok {
return v, true
}
return "", false
}
package integration
import (
	"encoding/base64"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
	"strconv"
	"testing"
	"github.com/smallstep/assert"
	"github.com/smallstep/cli/crypto/randutil"
	jose "gopkg.in/square/go-jose.v2"
)
func AssertFileExists(t *testing.T, path string, a ...interface{}) bool {
	info, err := os.Lstat(path)
	if err != nil {
		if os.IsNotExist(err) {
			assert.FatalError(t, err, fmt.Sprintf("unable to find file %q", path), a)
		}
		assert.FatalError(t, err, fmt.Sprintf("error when running os.Lstat(%q): %s", path, err), a)
	}
	assert.Fatal(t, !info.IsDir(), fmt.Sprintf("%q is a directory", path), a)
	assert.Equals(t, int(info.Mode()), 0600)
	return true
}
type JWKTest struct {
	name    string
	pubfile string
	prvfile string
	command CLICommand
}
func NewJWKTest(name string) JWKTest {
	pubfile := fmt.Sprintf("%s/%s-pub.json", TempDirectory, name)
	prvfile := fmt.Sprintf("%s/%s-prv.json", TempDirectory, name)
	cmd := NewCLICommand().setCommand("step crypto jwk create").setArguments(fmt.Sprintf("%s %s", pubfile, prvfile))
	return JWKTest{name, pubfile, prvfile, cmd}
}
func (j JWKTest) setFlag(flag, value string) JWKTest {
	return JWKTest{j.name, j.pubfile, j.prvfile, j.command.setFlag(flag, value)}
}
func (j JWKTest) cmd() string {
	return j.command.cmd()
}
func (j JWKTest) run() (CLIOutput, error) {
	return j.command.run()
}
func (j JWKTest) test(t *testing.T, msg ...interface{}) (CLIOutput, string) {
	var out CLIOutput
	var pass string
	t.Run(j.name, func(t *testing.T) {
		e, err := j.command.spawn()
		assert.FatalError(t, err)
		if _, ok := j.command.flags["no-password"]; !ok {
			pass, err = randutil.ASCII(16)
			assert.FatalError(t, err)
			e.ExpectTimeout("Please enter the password to encrypt the private JWK: ", DefaultTimeout)
			e.SendLine(pass)
			e.Interact()
		} else {
			e.Wait()
		}
		AssertFileExists(t, j.pubfile, fmt.Sprintf("step crypto jwk create should create public JWK at %s", j.pubfile))
		AssertFileExists(t, j.prvfile, fmt.Sprintf("step crypto jwk create should create private JWK at %s", j.prvfile))
		j.checkPublic(t)
		j.checkPrivate(t, pass)
	})
	return out, pass
}
func (j JWKTest) readJson(t *testing.T, name string) map[string]interface{} {
	dat, err := ioutil.ReadFile(name)
	assert.FatalError(t, err)
	m := make(map[string]interface{})
	assert.FatalError(t, json.Unmarshal(dat, &m))
	return m
}
func (j JWKTest) public(t *testing.T) map[string]interface{} {
	return j.readJson(t, j.pubfile)
}
func (j JWKTest) private(t *testing.T) map[string]interface{} {
	return j.readJson(t, j.prvfile)
}
func (j JWKTest) kty() string {
	kty := "EC"
	if v, ok := j.command.flags["kty"]; ok {
		kty = v
	} else if v, ok = j.command.flags["type"]; ok {
		kty = v
	}
	return kty
}