-
Notifications
You must be signed in to change notification settings - Fork 0
/
sspvo.go
115 lines (97 loc) · 2.01 KB
/
sspvo.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Copyright © 2020-present Artem V. Zaborskiy <ftomza@yandex.ru>. 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 sspvo
import (
"context"
"errors"
"net/http"
)
const (
VERSION = "1.0.0"
)
var (
ErrBadSign = errors.New("crypto: bad sign")
)
type Crypto interface {
GetVerifyCrypto(cert string) (Crypto, error)
GetCert() string
Hash(data []byte) (hash []byte)
Sign(digest []byte) (sign []byte, err error)
Verify(sign, digest []byte) (ok bool, err error)
}
type Client interface {
Send(ctx context.Context, msg Message) (res Response)
PrepareBody(msg Message) ([]byte, error)
}
type Token struct {
Header string
Payload string
Sign string
}
type FieldName string
const (
FieldOGRN FieldName = "OGRN"
FieldKPP FieldName = "KPP"
FieldCLS FieldName = "CLS"
FieldCert FieldName = "Cert64"
FieldToken FieldName = "token"
FieldAction FieldName = "action"
FieldDataType FieldName = "data_type"
FieldIdJWT FieldName = "IDJWT"
)
var AllField = []FieldName{
FieldOGRN,
FieldKPP,
FieldCLS,
FieldCert,
FieldToken,
FieldAction,
FieldDataType,
FieldIdJWT,
}
func (e FieldName) IsValid() bool {
switch e {
case FieldOGRN,
FieldKPP,
FieldCLS,
FieldCert,
FieldToken,
FieldAction,
FieldDataType,
FieldIdJWT:
return true
}
return false
}
func (e FieldName) String() string {
return string(e)
}
type JWTFields map[FieldName]interface{}
type Fields func(JWTFields)
func SetField(field FieldName, value interface{}) Fields {
return func(f JWTFields) {
f[field] = value
}
}
type Message interface {
UpdateJWTFields(fields ...Fields) Message
PathMethod() string
GetJWT() ([]byte, error)
Response() Response
}
type ClientResponse struct {
Code int
Body []byte
Header http.Header
}
type Response interface {
ClientResponse() *ClientResponse
SetClientResponse(resp *ClientResponse)
SetError(err error)
Error() error
Data() ([]byte, error)
}