/
openpgp.go
47 lines (37 loc) · 1.01 KB
/
openpgp.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
// SPDX-FileCopyrightText: 2023 Steffen Vogel <post@steffenvogel.de>
// SPDX-License-Identifier: Apache-2.0
package provider
import (
"fmt"
)
//nolint:unused
type openpgpSlotRef struct {
SerialNo int `koanf:"serial_no"`
Slot int `koanf:"slot"`
}
//nolint:unused
func (s *openpgpSlotRef) MarshalText() (text []byte, err error) {
str := fmt.Sprintf("ecdh:%s:sk:openpgp:%d:%d", "Secp256r1", s.SerialNo, s.Slot)
return []byte(str), nil
}
//nolint:unused
func (s *openpgpSlotRef) UnmarshalText(text []byte) error {
var curve string
if n, err := fmt.Sscanf(string(text), "ecdh:%s:sk:openpgp:%d:%d", &curve, &s.SerialNo, &s.Slot); err != nil {
return fmt.Errorf("%w: %w", ErrParse, err)
} else if n != 3 {
return ErrParse
}
switch curve {
case "Secp256r1":
default:
return fmt.Errorf("%w: %s", ErrUnsupportedCurve, curve)
}
return nil
}
// var _ Provider = (*openpgpProvider)(nil)
// type openpgpProvider struct{}
// //nolint:gochecknoinits
// func init() {
// Register("OpenPGP", &openpgpProvider{})
// }