diff --git a/crtutil/key.go b/crtutil/key.go index 5540fa5..9425d52 100644 --- a/crtutil/key.go +++ b/crtutil/key.go @@ -11,29 +11,47 @@ import ( ) // ParseKeyFile parses an unencrypted crypto.PrivateKey from the given file. +// Deprecated: use ReadFileAsSigner instead. func ParseKeyFile(fpath string) (crypto.PrivateKey, error) { + return ReadFileAsSigner(fpath) +} + +// ReadFileAsSigner read a crypto.PrivateKey from the given file. +func ReadFileAsSigner(fpath string) (crypto.PrivateKey, error) { f, err := ioutil.ReadFile(fpath) if err != nil { return nil, err } - return ParseKeyBytes(f, false) + return ReadBytesAsSigner(f, false) } -// ParseKeyFileWithPass parses an unencrypted crypto.PrivateKey from the given file. +// ParseKeyFileWithPass read a crypto.PrivateKey from the given file. +// Deprecated: use ReadFileAsSignerWithPass instead. func ParseKeyFileWithPass(keyPath, keyPass string) (crypto.PrivateKey, error) { + return ReadFileAsSignerWithPass(keyPath, keyPass) +} + +// ReadFileAsSignerWithPass read a crypto.PrivateKey from the given file. +func ReadFileAsSignerWithPass(keyPath, keyPass string) (crypto.PrivateKey, error) { f, err := ioutil.ReadFile(keyPath) if err != nil { return nil, err } - return parseKeyBytes(f, []byte(keyPass), false) + return readBytesAsSigner(f, []byte(keyPass), false) } -// ParseKeyBytes parses an unencrypted crypto.PrivateKey from the given data. +// ParseKeyBytes read a crypto.PrivateKey from the given data. +// Deprecated: use ReadBytesAsSigner instead. func ParseKeyBytes(data []byte, isBase64 bool) (crypto.PrivateKey, error) { - return parseKeyBytes(data, nil, isBase64) + return readBytesAsSigner(data, nil, isBase64) +} + +// ReadBytesAsSigner read a crypto.PrivateKey from the given data. +func ReadBytesAsSigner(data []byte, isBase64 bool) (crypto.PrivateKey, error) { + return readBytesAsSigner(data, nil, isBase64) } -func parseKeyBytes(key, keypass []byte, isBase64 bool) (crypto.PrivateKey, error) { +func readBytesAsSigner(key, keypass []byte, isBase64 bool) (crypto.PrivateKey, error) { var err error dkeystr := key diff --git a/crtutil/key_test.go b/crtutil/key_test.go index 7448503..24788f6 100644 --- a/crtutil/key_test.go +++ b/crtutil/key_test.go @@ -9,7 +9,7 @@ import ( ) func TestParseKeyFile(t *testing.T) { - prik, err := ParseKeyFile("testdata/server-rsa.key") + prik, err := ReadFileAsSigner("testdata/server-rsa.key") assert.NoError(t, err) _, ok := prik.(*rsa.PrivateKey) @@ -17,7 +17,7 @@ func TestParseKeyFile(t *testing.T) { } func TestParseKeyFileWithPass(t *testing.T) { - prik, err := ParseKeyFileWithPass("testdata/server-rsa.key", "") + prik, err := ReadFileAsSignerWithPass("testdata/server-rsa.key", "") assert.NoError(t, err) _, ok := prik.(*rsa.PrivateKey) @@ -28,7 +28,7 @@ func TestParseKeyBytes(t *testing.T) { f, err := ioutil.ReadFile("testdata/server-rsa-base64.key") assert.NoError(t, err) - prik, err := ParseKeyBytes(f, true) + prik, err := ReadBytesAsSigner(f, true) assert.NoError(t, err) _, ok := prik.(*rsa.PrivateKey)