Skip to content

Commit

Permalink
fix: set non-exportable type
Browse files Browse the repository at this point in the history
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
  • Loading branch information
JeyJeyGao committed Jul 31, 2023
1 parent 5dea9e5 commit b3de155
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
8 changes: 4 additions & 4 deletions internal/encoding/asn1/asn1.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ var (
ErrInvalidOffset = asn1.StructuralError{Msg: "invalid offset"}
)

// Value represents an ASN.1 value.
type Value interface {
// value represents an ASN.1 value.
type value interface {
// Encode encodes the value to the value writer in DER.
Encode(ValueWriter) error
Encode(valueWriter) error

// EncodedLen returns the length in bytes of the encoded data.
EncodedLen() int
Expand All @@ -42,7 +42,7 @@ func ConvertToDER(ber []byte) ([]byte, error) {
}

// decode decodes BER-encoded ASN.1 data structures.
func decode(r ReadOnlySlice) (Value, error) {
func decode(r ReadOnlySlice) (value, error) {
identifier, isPrimitiveValue, err := identifierValue(r)
if err != nil {
return nil, err
Expand Down
16 changes: 8 additions & 8 deletions internal/encoding/asn1/constructed.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package asn1

// ConstructedValue represents a value in constructed encoding.
type ConstructedValue struct {
// constructedValue represents a value in constructed encoding.
type constructedValue struct {
identifier ReadOnlySlice
length int
members []Value
members []value
}

// newConstructedValue builds the constructed value.
func newConstructedValue(identifier ReadOnlySlice, expectedLength int, content ReadOnlySlice) (Value, error) {
var members []Value
func newConstructedValue(identifier ReadOnlySlice, expectedLength int, content ReadOnlySlice) (value, error) {
var members []value
encodedLength := 0
for content.Offset() < content.Length() {
value, err := decode(content)
Expand All @@ -20,15 +20,15 @@ func newConstructedValue(identifier ReadOnlySlice, expectedLength int, content R
encodedLength += value.EncodedLen()
}

return ConstructedValue{
return constructedValue{
identifier: identifier,
length: encodedLength,
members: members,
}, nil
}

// Encode encodes the constructed value to the value writer in DER.
func (v ConstructedValue) Encode(w ValueWriter) error {
func (v constructedValue) Encode(w valueWriter) error {
_, err := w.ReadFrom(v.identifier)
if err != nil {
return err
Expand All @@ -45,6 +45,6 @@ func (v ConstructedValue) Encode(w ValueWriter) error {
}

// EncodedLen returns the length in bytes of the encoded data.
func (v ConstructedValue) EncodedLen() int {
func (v constructedValue) EncodedLen() int {
return v.identifier.Length() + encodedLengthSize(v.length) + v.length
}
4 changes: 2 additions & 2 deletions internal/encoding/asn1/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package asn1

import "io"

// ValueWriter is the interface for writing a value.
type ValueWriter interface {
// valueWriter is the interface for writing a value.
type valueWriter interface {
io.ReaderFrom
io.ByteWriter
}
12 changes: 6 additions & 6 deletions internal/encoding/asn1/primitive.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package asn1

// PrimitiveValue represents a value in primitive encoding.
type PrimitiveValue struct {
// primitiveValue represents a value in primitive encoding.
type primitiveValue struct {
identifier ReadOnlySlice
content ReadOnlySlice
}

// newPrimitiveValue builds the primitive value.
func newPrimitiveValue(identifier ReadOnlySlice, content ReadOnlySlice) (Value, error) {
return PrimitiveValue{
func newPrimitiveValue(identifier ReadOnlySlice, content ReadOnlySlice) (value, error) {
return primitiveValue{
identifier: identifier,
content: content,
}, nil
}

// Encode encodes the primitive value to the value writer in DER.
func (v PrimitiveValue) Encode(w ValueWriter) error {
func (v primitiveValue) Encode(w valueWriter) error {
_, err := w.ReadFrom(v.identifier)
if err != nil {
return err
Expand All @@ -28,6 +28,6 @@ func (v PrimitiveValue) Encode(w ValueWriter) error {
}

// EncodedLen returns the length in bytes of the encoded data.
func (v PrimitiveValue) EncodedLen() int {
func (v primitiveValue) EncodedLen() int {
return v.identifier.Length() + encodedLengthSize(v.content.Length()) + v.content.Length()
}
5 changes: 3 additions & 2 deletions internal/encoding/asn1/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ func (r *readOnlySlice) ReadByte() (byte, error) {
if r.offset >= len(r.data) {
return 0, ErrEarlyEOF
}
defer func() { r.offset++ }()
return r.data[r.offset], nil
b := r.data[r.offset]
r.offset++
return b, nil
}

func (r *readOnlySlice) Read(p []byte) (int, error) {
Expand Down

0 comments on commit b3de155

Please sign in to comment.