Skip to content

Commit

Permalink
std: update content type enum
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Feb 7, 2025
1 parent 13cab72 commit acda197
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
13 changes: 8 additions & 5 deletions std/ndn/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ const MaxNDNPacketSize = 8800
type ContentType uint64

const (
ContentTypeBlob ContentType = 0
ContentTypeLink ContentType = 1
ContentTypeKey ContentType = 2
ContentTypeNack ContentType = 3
ContentTypeSigKey ContentType = 9
ContentTypeBlob ContentType = 0
ContentTypeLink ContentType = 1
ContentTypeKey ContentType = 2
ContentTypeNack ContentType = 3
ContentTypeManifest ContentType = 4
ContentTypePrefixAnnouncement ContentType = 5
ContentTypeEncapsulatedData ContentType = 6
ContentTypeSigningKey ContentType = 9
)

// SigType represents the type of signature.
Expand Down
2 changes: 1 addition & 1 deletion std/security/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func getPubKey(data ndn.Data) ([]byte, enc.Name, error) {
return nil, nil, err
}
return pub, keyName, nil
case ndn.ContentTypeSigKey:
case ndn.ContentTypeSigningKey:
// Content is private key, parse the signer
signer, err := sig.UnmarshalSecret(data)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion std/security/decode_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func DecodeFile(content []byte) (signers []ndn.Signer, certs [][]byte, err error
switch contentType {
case ndn.ContentTypeKey: // cert
certs = append(certs, wire)
case ndn.ContentTypeSigKey: // key
case ndn.ContentTypeSigningKey: // key
key, err := sig.UnmarshalSecret(data)
if err != nil || key == nil {
log.Warn(nil, "Failed to decode key", "name", data.Name(), "err", err)
Expand Down
2 changes: 1 addition & 1 deletion std/security/pem.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func PemEncode(raw []byte) ([]byte, error) {
switch contentType {
case ndn.ContentTypeKey:
pemType = PEM_TYPE_CERT
case ndn.ContentTypeSigKey:
case ndn.ContentTypeSigningKey:
pemType = PEM_TYPE_SECRET
default:
return nil, fmt.Errorf("unsupported content type")
Expand Down
4 changes: 2 additions & 2 deletions std/security/signer/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func MarshalSecret(key ndn.Signer) (enc.Wire, error) {

// Encode key data packet
cfg := &ndn.DataConfig{
ContentType: optional.Some(ndn.ContentTypeSigKey),
ContentType: optional.Some(ndn.ContentTypeSigningKey),
}
data, err := spec.Spec{}.MakeData(name, cfg, enc.Wire{sk}, key)
if err != nil {
Expand All @@ -52,7 +52,7 @@ func MarshalSecret(key ndn.Signer) (enc.Wire, error) {
// UnmarshalSecret decodes a signed NDN Data packet to a key secret.
func UnmarshalSecret(data ndn.Data) (ndn.Signer, error) {
// Check data content type
if ctype, ok := data.ContentType().Get(); !ok || ctype != ndn.ContentTypeSigKey {
if ctype, ok := data.ContentType().Get(); !ok || ctype != ndn.ContentTypeSigningKey {
return nil, ndn.ErrInvalidValue{Item: "content type"}
}

Expand Down
2 changes: 1 addition & 1 deletion std/security/signer/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestMarshalSecret(t *testing.T) {
// check output data
data, _, err := spec.Spec{}.ReadData(enc.NewWireView(wire))
require.NoError(t, err)
require.Equal(t, ndn.ContentTypeSigKey, data.ContentType().Unwrap())
require.Equal(t, ndn.ContentTypeSigningKey, data.ContentType().Unwrap())
require.Equal(t, RSA_KEY_NAME, data.Name())
require.Equal(t, secret, data.Content().Join())
}
Expand Down

0 comments on commit acda197

Please sign in to comment.