Files
kmip/request.go

138 lines
5.8 KiB
Go

package kmip
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import (
"time"
)
// Request is a Request Message Structure
type Request struct {
Tag `kmip:"REQUEST_MESSAGE"`
Header RequestHeader `kmip:"REQUEST_HEADER,required"`
BatchItems []RequestBatchItem `kmip:"REQUEST_BATCH_ITEM,required"`
}
// RequestHeader is a Request Header Structure
type RequestHeader struct {
Tag `kmip:"REQUEST_HEADER"`
Version ProtocolVersion `kmip:"PROTOCOL_VERSION,required"`
MaxResponseSize int32 `kmip:"MAXIMUM_RESPONSE_SIZE"`
ClientCorrelationValue string `kmip:"CLIENT_CORRELATION_VALUE"`
ServerCorrelationValue string `kmip:"SERVER_CORRELATION_VALUE"`
AsynchronousIndicator bool `kmip:"ASYNCHRONOUS_INDICATOR"`
AttestationCapableIndicator bool `kmip:"ATTESTATION_CAPABLE_INDICATOR"`
AttestationType []Enum `kmip:"ATTESTATION_TYPE"`
Authentication Authentication `kmip:"AUTHENTICATION"`
BatchErrorContinuationOption Enum `kmip:"BATCH_ERROR_CONTINUATION_OPTION"`
BatchOrderOption bool `kmip:"BATCH_ORDER_OPTION"`
TimeStamp time.Time `kmip:"TIME_STAMP"`
BatchCount int32 `kmip:"BATCH_COUNT,required"`
}
// RequestBatchItem is a Request Batch Item Structure
type RequestBatchItem struct {
Tag `kmip:"REQUEST_BATCH_ITEM"`
Operation Enum `kmip:"OPERATION,required"`
UniqueID []byte `kmip:"UNIQUE_BATCH_ITEM_ID"`
RequestPayload interface{} `kmip:"REQUEST_PAYLOAD,required"`
MessageExtension MessageExtension `kmip:"MESSAGE_EXTENSION"`
}
// BuildFieldValue builds value for RequestPayload based on Operation
func (bi *RequestBatchItem) BuildFieldValue(name string) (v interface{}, err error) {
switch bi.Operation {
case OPERATION_CREATE:
v = &CreateRequest{}
case OPERATION_GET:
v = &GetRequest{}
case OPERATION_GET_ATTRIBUTES:
v = &GetAttributesRequest{}
case OPERATION_GET_ATTRIBUTE_LIST:
v = &GetAttributeListRequest{}
case OPERATION_DESTROY:
v = &DestroyRequest{}
case OPERATION_DISCOVER_VERSIONS:
v = &DiscoverVersionsRequest{}
case OPERATION_REGISTER:
v = &RegisterRequest{}
case OPERATION_ACTIVATE:
v = &ActivateRequest{}
case OPERATION_LOCATE:
v = &LocateRequest{}
case OPERATION_REVOKE:
v = &RevokeRequest{}
case OPERATION_QUERY:
v = &QueryRequest{}
default:
// For unsupported operations, use a generic payload to allow decoding to complete
// The server will handle the "unsupported operation" error in the handler phase
v = &GenericRequestPayload{}
}
return
}
// ProtocolVersion is a Protocol Version structure
type ProtocolVersion struct {
Tag `kmip:"PROTOCOL_VERSION"`
Major int32 `kmip:"PROTOCOL_VERSION_MAJOR"`
Minor int32 `kmip:"PROTOCOL_VERSION_MINOR"`
}
// MessageExtension is a Message Extension structure in a Batch Item
type MessageExtension struct {
Tag `kmip:"MESSAGE_EXTENSION"`
VendorIdentification string `kmip:"VENDOR_IDENTIFICATION,required"`
CriticalityIndicator bool `kmip:"CRITICALITY_INDICATOR,required"`
VendorExtension interface{} `kmip:"-,skip"`
}
// RevocationReason is a Revocation Reason structure
type RevocationReason struct {
Tag `kmip:"REVOCATION_REASON"`
RevocationReasonCode Enum `kmip:"REVOCATION_REASON_CODE"`
RevocationMessage string `kmip:"REVOCATION_REASON"`
}
// GenericRequestPayload is used for unsupported operations to allow decoding to complete
// The server will handle the "unsupported operation" error in the handler phase
type GenericRequestPayload struct {
Tag `kmip:"REQUEST_PAYLOAD"`
// Common fields that might appear in any request payload
UniqueIdentifier string `kmip:"UNIQUE_IDENTIFIER"`
ObjectType Enum `kmip:"OBJECT_TYPE"`
TemplateAttribute TemplateAttribute `kmip:"TEMPLATE_ATTRIBUTE"`
KeyFormatType Enum `kmip:"KEY_FORMAT_TYPE"`
KeyWrapType Enum `kmip:"KEY_WRAP_TYPE"`
KeyCompressionType Enum `kmip:"KEY_COMPRESSION_TYPE"`
KeyWrappingSpec KeyWrappingSpecification `kmip:"KEY_WRAPPING_SPECIFICATION"`
QueryFunctions []Enum `kmip:"QUERY_FUNCTION"`
ProtocolVersions []ProtocolVersion `kmip:"PROTOCOL_VERSION"`
CryptoParams CryptoParams `kmip:"CRYPTOGRAPHIC_PARAMETERS"`
Data []byte `kmip:"DATA"`
IVCounterNonce []byte `kmip:"IV_COUNTER_NONCE"`
CorrelationValue []byte `kmip:"CORRELATION_VALUE"`
InitIndicator bool `kmip:"INIT_INDICATOR"`
FinalIndicator bool `kmip:"FINAL_INDICATOR"`
AdditionalData []byte `kmip:"AUTHENTICATED_ENCRYPTION_ADDITIONAL_DATA"`
AuthTag []byte `kmip:"AUTHENTICATED_ENCRYPTION_TAG"`
SignatureData []byte `kmip:"SIGNATURE_DATA"`
MACData []byte `kmip:"MAC_DATA"`
SymmetricKey SymmetricKey `kmip:"SYMMETRIC_KEY"`
PrivateKey PrivateKey `kmip:"PRIVATE_KEY"`
PublicKey PublicKey `kmip:"PUBLIC_KEY"`
CommonTemplateAttribute TemplateAttribute `kmip:"COMMON_TEMPLATE_ATTRIBUTE"`
PrivateKeyTemplateAttribute TemplateAttribute `kmip:"PRIVATE_KEY_TEMPLATE_ATTRIBUTE"`
PublicKeyTemplateAttribute TemplateAttribute `kmip:"PUBLIC_KEY_TEMPLATE_ATTRIBUTE"`
}