mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 04:06:18 +08:00
Merge branch 'main' of https://github.com/emmansun/gmsm
This commit is contained in:
commit
26408e6993
@ -52,35 +52,11 @@ func ParsePKIXPublicKey(derBytes []byte) (interface{}, error) {
|
|||||||
} else if len(rest) != 0 {
|
} else if len(rest) != 0 {
|
||||||
return nil, errors.New("x509: trailing data after ASN.1 of public-key")
|
return nil, errors.New("x509: trailing data after ASN.1 of public-key")
|
||||||
}
|
}
|
||||||
|
algo := getPublicKeyAlgorithmFromOID(pki.Algorithm.Algorithm)
|
||||||
if !pki.Algorithm.Algorithm.Equal(oidPublicKeyECDSA) {
|
if algo == UnknownPublicKeyAlgorithm {
|
||||||
return x509.ParsePKIXPublicKey(derBytes)
|
return nil, errors.New("x509: unknown public key algorithm")
|
||||||
}
|
}
|
||||||
keyData := &pki
|
return parsePublicKey(algo, &pki)
|
||||||
asn1Data := keyData.PublicKey.RightAlign()
|
|
||||||
paramsData := keyData.Algorithm.Parameters.FullBytes
|
|
||||||
namedCurveOID := new(asn1.ObjectIdentifier)
|
|
||||||
rest, err := asn1.Unmarshal(paramsData, namedCurveOID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("x509: failed to parse ECDSA parameters as named curve")
|
|
||||||
}
|
|
||||||
if len(rest) != 0 {
|
|
||||||
return nil, errors.New("x509: trailing data after ECDSA parameters")
|
|
||||||
}
|
|
||||||
if !namedCurveOID.Equal(oidNamedCurveP256SM2) {
|
|
||||||
return x509.ParsePKIXPublicKey(derBytes)
|
|
||||||
}
|
|
||||||
namedCurve := sm2.P256()
|
|
||||||
x, y := elliptic.Unmarshal(namedCurve, asn1Data)
|
|
||||||
if x == nil {
|
|
||||||
return nil, errors.New("x509: failed to unmarshal elliptic curve point")
|
|
||||||
}
|
|
||||||
pub := &ecdsa.PublicKey{
|
|
||||||
Curve: namedCurve,
|
|
||||||
X: x,
|
|
||||||
Y: y,
|
|
||||||
}
|
|
||||||
return pub, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshalPublicKey(pub interface{}) (publicKeyBytes []byte, publicKeyAlgorithm pkix.AlgorithmIdentifier, err error) {
|
func marshalPublicKey(pub interface{}) (publicKeyBytes []byte, publicKeyAlgorithm pkix.AlgorithmIdentifier, err error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user