2022-08-03 12:38:36 +00:00
|
|
|
/*
|
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2022-11-28 16:10:46 +00:00
|
|
|
const CobsDelimiter = 0x00
|
|
|
|
|
2022-11-21 07:26:50 +00:00
|
|
|
type Command struct {
|
|
|
|
Announce *messages.CommandAnnounce
|
|
|
|
Command interface{}
|
|
|
|
}
|
|
|
|
|
2022-11-28 16:10:46 +00:00
|
|
|
func (c *Command) String() string {
|
|
|
|
return fmt.Sprintf("Cmd[announce={%s}, data={%s}]", c.Announce, c.Command)
|
|
|
|
}
|
|
|
|
|
2022-11-21 07:26:50 +00:00
|
|
|
type Response struct {
|
|
|
|
Announce *messages.ResponseAnnounce
|
|
|
|
Response interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Response) String() string {
|
2022-11-28 16:10:46 +00:00
|
|
|
return fmt.Sprintf("Rsp[announce={%s}, data={%s}]", r.Announce, r.Response)
|
2022-11-21 07:26:50 +00:00
|
|
|
}
|
|
|
|
|
2022-08-03 12:38:36 +00:00
|
|
|
// Handler is responsible for parsing incoming frames and calling commands
|
|
|
|
type Handler interface {
|
2022-11-28 16:10:46 +00:00
|
|
|
// HandleCommandAnnounce handles the initial announcement of a command.
|
2022-11-21 07:26:50 +00:00
|
|
|
HandleCommandAnnounce([]byte) error
|
2022-11-28 16:10:46 +00:00
|
|
|
// HandleCommand handles the command data.
|
2022-11-21 07:26:50 +00:00
|
|
|
HandleCommand([]byte) error
|
2022-11-28 16:10:46 +00:00
|
|
|
// ResponseAnnounce generates the announcement for a response.
|
2022-11-21 07:26:50 +00:00
|
|
|
ResponseAnnounce() ([]byte, error)
|
2022-11-28 16:10:46 +00:00
|
|
|
// ResponseData generates the response data.
|
2022-11-21 07:26:50 +00:00
|
|
|
ResponseData() ([]byte, error)
|
2022-08-03 12:38:36 +00:00
|
|
|
}
|