INNER CODE UNIT · Go

parsePrivateKeyOpenSSHPEM

hashicorp/terraform-provider-tls · internal/provider/common_key.go:121

func parsePrivateKeyOpenSSHPEM(keyOpenSSHPEMBytes []byte) (crypto.PrivateKey, Algorithm, error) {
	prvKey, err := ssh.ParseRawPrivateKey(keyOpenSSHPEMBytes)
	if err != nil {
		return nil, "", fmt.Errorf("failed to parse openssh private key: %w", err)
	}

	algorithm, err := privateKeyToAlgorithm(prvKey)
	if err != nil {
		return nil, "", fmt.Errorf("failed to determine key algorithm for private key of type %T: %w", prvKey, err)
	}

	return prvKey, algorithm, nil
}

// privateKeyToPublicKey takes a crypto.PrivateKey and extracts the corresponding crypto.PublicKey,
// after having figured out its type.
func privateKeyToPublicKey(prvKey crypto.PrivateKey) (crypto.PublicKey, error) {
	signer, ok := prvKey.(crypto.Signer)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…