forked from lorenzodonini/ocpp-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
certificate_signed.go
83 lines (64 loc) · 3.12 KB
/
certificate_signed.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
package security
import (
"reflect"
"gopkg.in/go-playground/validator.v9"
"github.com/lorenzodonini/ocpp-go/ocpp2.0.1/types"
)
// -------------------- Certificate Signed (CSMS -> CS) --------------------
const CertificateSignedFeatureName = "CertificateSigned"
// Status returned in response to CertificateSignedRequest, that indicates whether certificate signing has been accepted or rejected.
type CertificateSignedStatus string
const (
CertificateSignedStatusAccepted CertificateSignedStatus = "Accepted"
CertificateSignedStatusRejected CertificateSignedStatus = "Rejected"
)
func isValidCertificateSignedStatus(fl validator.FieldLevel) bool {
status := CertificateSignedStatus(fl.Field().String())
switch status {
case CertificateSignedStatusAccepted, CertificateSignedStatusRejected:
return true
default:
return false
}
}
// The field definition of the CertificateSignedRequest PDU sent by the CSMS to the Charging Station.
type CertificateSignedRequest struct {
CertificateChain string `json:"certificateChain" validate:"required,max=10000"`
TypeOfCertificate types.CertificateSigningUse `json:"certificateType,omitempty" validate:"omitempty,certificateSigningUse16"`
}
// The field definition of the CertificateSignedResponse payload sent by the Charging Station to the CSMS in response to a CertificateSignedRequest.
type CertificateSignedResponse struct {
Status CertificateSignedStatus `json:"status" validate:"required,certificateSignedStatus16"`
StatusInfo *types.StatusInfo `json:"statusInfo,omitempty" validate:"omitempty"`
}
// During the a certificate update procedure, the CSMS sends a new certificate, signed by a CA,
// to the Charging Station with a CertificateSignedRequest.
// The Charging Station verifies the signed certificate, installs it locally and responds with
// a CertificateSignedResponse to the the CSMS with the status Accepted or Rejected.
type CertificateSignedFeature struct{}
func (f CertificateSignedFeature) GetFeatureName() string {
return CertificateSignedFeatureName
}
func (f CertificateSignedFeature) GetRequestType() reflect.Type {
return reflect.TypeOf(CertificateSignedRequest{})
}
func (f CertificateSignedFeature) GetResponseType() reflect.Type {
return reflect.TypeOf(CertificateSignedResponse{})
}
func (r CertificateSignedRequest) GetFeatureName() string {
return CertificateSignedFeatureName
}
func (c CertificateSignedResponse) GetFeatureName() string {
return CertificateSignedFeatureName
}
// Creates a new CertificateSignedRequest, containing all required fields. Additional optional fields may be set afterwards.
func NewCertificateSignedRequest(certificateChain string) *CertificateSignedRequest {
return &CertificateSignedRequest{CertificateChain: certificateChain}
}
// Creates a new CertificateSignedResponse, containing all required fields. There are no optional fields for this message.
func NewCertificateSignedResponse(status CertificateSignedStatus) *CertificateSignedResponse {
return &CertificateSignedResponse{Status: status}
}
func init() {
_ = types.Validate.RegisterValidation("certificateSignedStatus16", isValidCertificateSignedStatus)
}