forked from gokalkan/gokalkan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify.go
42 lines (34 loc) · 1.29 KB
/
verify.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
package gokalkan
import (
"encoding/base64"
"github.com/snurbol/gokalkan/ckalkan"
)
// Verify обеспечивает проверку подписи CMS в base64.
func (cli *Client) Verify(signature []byte) (string, error) {
signatureB64 := base64.StdEncoding.EncodeToString(signature)
flags := ckalkan.FlagSignCMS | ckalkan.FlagInBase64 | ckalkan.FlagOutBase64
resp, err := cli.kc.VerifyData(signatureB64, "", "", flags)
if err != nil {
return "", err
}
return string(resp.Info), err
}
// VerifyXML обеспечивает проверку подписи данных в формате XML.
func (cli *Client) VerifyXML(signedXML string) (result string, err error) {
return cli.kc.VerifyXML(signedXML, "", 0)
}
// VerifyDetached обеспечивает проверку отделенной подписи
// CMS (detached signature) в base64.
func (cli *Client) VerifyDetached(signature, data []byte) (string, error) {
signatureB64 := base64.StdEncoding.EncodeToString(signature)
dataB64 := base64.StdEncoding.EncodeToString(data)
flags := ckalkan.FlagSignCMS
flags |= ckalkan.FlagInBase64
flags |= ckalkan.FlagIn2Base64
flags |= ckalkan.FlagDetachedData
resp, err := cli.kc.VerifyData(signatureB64, dataB64, "", flags)
if err != nil {
return "", err
}
return string(resp.Info), err
}