forked from notaryproject/notation-core-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
- Loading branch information
Showing
6 changed files
with
84 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
package asn1 | ||
|
||
import "bytes" | ||
|
||
// primitiveValue represents a value in primitive encoding. | ||
type primitiveValue struct { | ||
identifier readOnlySlice | ||
content readOnlySlice | ||
identifier []byte | ||
content []byte | ||
} | ||
|
||
// newPrimitiveValue builds the primitive value. | ||
func newPrimitiveValue(identifier readOnlySlice, content readOnlySlice) value { | ||
func newPrimitiveValue(identifier []byte, content []byte) value { | ||
return primitiveValue{ | ||
identifier: identifier, | ||
content: content, | ||
} | ||
} | ||
|
||
// Encode encodes the primitive value to the value writer in DER. | ||
func (v primitiveValue) Encode(w valueWriter) error { | ||
_, err := w.ReadFrom(v.identifier) | ||
func (v primitiveValue) Encode(w *bytes.Buffer) error { | ||
_, err := w.Write(v.identifier) | ||
if err != nil { | ||
return err | ||
} | ||
if err = encodeLength(w, v.content.Length()); err != nil { | ||
if err = encodeLen(w, len(v.content)); err != nil { | ||
return err | ||
} | ||
_, err = w.ReadFrom(v.content) | ||
_, err = w.Write(v.content) | ||
return err | ||
} | ||
|
||
// EncodedLen returns the length in bytes of the encoded data. | ||
func (v primitiveValue) EncodedLen() int { | ||
return v.identifier.Length() + encodedLengthSize(v.content.Length()) + v.content.Length() | ||
return len(v.identifier) + encodedLenSize(len(v.content)) + len(v.content) | ||
} |
Oops, something went wrong.