Jan Dittberner
f0d456dd13
- add a client generated command ID for tracing commands and responses - define protocol delimiter in protocol.CobsDelimiter - apply code simplifications suggested by golangci-lint - add Makefile - add compile time build information for signer binary - make sure that dependencies for msgpackgen survive go mod tidy - extract MsgPackHandler into its own file - add CRL number to fetch CRL response - remove port.Flush() to avoid removing written data before it reaches the client
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
/*
|
|
Copyright 2022 CAcert Inc.
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
// Package protocol handles the protocol message marshaling and unmarshalling.
|
|
package protocol
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.cacert.org/cacert-gosigner/pkg/messages"
|
|
)
|
|
|
|
const CobsDelimiter = 0x00
|
|
|
|
type Command struct {
|
|
Announce *messages.CommandAnnounce
|
|
Command interface{}
|
|
}
|
|
|
|
func (c *Command) String() string {
|
|
return fmt.Sprintf("Cmd[announce={%s}, data={%s}]", c.Announce, c.Command)
|
|
}
|
|
|
|
type Response struct {
|
|
Announce *messages.ResponseAnnounce
|
|
Response interface{}
|
|
}
|
|
|
|
func (r *Response) String() string {
|
|
return fmt.Sprintf("Rsp[announce={%s}, data={%s}]", r.Announce, r.Response)
|
|
}
|
|
|
|
// Handler is responsible for parsing incoming frames and calling commands
|
|
type Handler interface {
|
|
// HandleCommandAnnounce handles the initial announcement of a command.
|
|
HandleCommandAnnounce([]byte) error
|
|
// HandleCommand handles the command data.
|
|
HandleCommand([]byte) error
|
|
// ResponseAnnounce generates the announcement for a response.
|
|
ResponseAnnounce() ([]byte, error)
|
|
// ResponseData generates the response data.
|
|
ResponseData() ([]byte, error)
|
|
}
|