-
Notifications
You must be signed in to change notification settings - Fork 1
/
digest.go
48 lines (41 loc) · 1.1 KB
/
digest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright © 2020-present Artem V. Zaborskiy <[email protected]>. All rights reserved.
*
* This source code is licensed under the Apache 2.0 license found
* in the LICENSE file in the root directory of this source tree.
*/
package gost_crypto
import (
"encoding/asn1"
"errors"
"hash"
"github.com/ftomza/gogost/gost34112012256"
"github.com/ftomza/gogost/gost34112012512"
)
type algorithmParam struct {
Curve asn1.ObjectIdentifier
Digest asn1.ObjectIdentifier
}
func ParsePKIXPublicKeyHash(derBytes []byte) (hash hash.Hash, err error) {
pki, err := getPublicKeyInfo(derBytes)
if err != nil {
return nil, err
}
var params algorithmParam
rest, err := asn1.Unmarshal(pki.Algorithm.Parameters.FullBytes, ¶ms)
if err != nil {
return nil, err
}
if len(rest) != 0 {
return nil, errors.New("x509: trailing data after ASN.1 of Algorithm Parameters")
}
switch {
case params.Digest.Equal(oidtc26gost341112256):
hash = gost34112012256.New()
case params.Digest.Equal(oidtc26gost341112512):
hash = gost34112012512.New()
default:
return nil, errors.New("x509: unknown algorithm")
}
return
}