some godoc
This commit is contained in:
@ -34,6 +34,11 @@ func (certificate Certificate) Type() byte {
|
||||
return certificate[0]
|
||||
}
|
||||
|
||||
//
|
||||
// Look up the length of the certificate, reporting
|
||||
// errors if the certificate is invalid or the specified
|
||||
// length does not match the provided data.
|
||||
//
|
||||
func (certificate Certificate) Length() (int, error) {
|
||||
if len(certificate) < 3 {
|
||||
// log
|
||||
@ -52,6 +57,10 @@ func (certificate Certificate) Length() (int, error) {
|
||||
return length, nil
|
||||
}
|
||||
|
||||
//
|
||||
// Return the certificate data and any errors
|
||||
// encountered by Length.
|
||||
//
|
||||
func (certificate Certificate) Data() ([]byte, error) {
|
||||
length, err := certificate.Length()
|
||||
if err != nil {
|
||||
@ -81,6 +90,10 @@ func (certificate Certificate) SignatureSize() int {
|
||||
return sizes[int(certificate.Type())]
|
||||
}
|
||||
|
||||
//
|
||||
// Read a certificate from a slice of bytes, returning
|
||||
// any extra data on the end of the slice.
|
||||
//
|
||||
func ReadCertificate(data []byte) (Certificate, []byte, error) {
|
||||
certificate := Certificate(data)
|
||||
length, err := certificate.Length()
|
||||
|
@ -6,6 +6,13 @@ import (
|
||||
|
||||
type Date [8]byte
|
||||
|
||||
//
|
||||
// Time takes the value stored in date as an 8
|
||||
// byte big-endian integer representing the
|
||||
// number of milliseconds since the beginning
|
||||
// of unix time and converts it to a go time.Time
|
||||
// struct.
|
||||
//
|
||||
func (date Date) Time() time.Time {
|
||||
seconds := Integer(date[:])
|
||||
return time.Unix(0, int64(seconds*1000000))
|
||||
|
@ -4,6 +4,11 @@ import (
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
//
|
||||
// Interpret a slice of bytes from length 1
|
||||
// to length 8 as a big-endian integer and
|
||||
// return an int representation.
|
||||
//
|
||||
func Integer(number []byte) int {
|
||||
num_len := len(number)
|
||||
if num_len < 8 {
|
||||
|
@ -6,6 +6,11 @@ import (
|
||||
|
||||
type String []byte
|
||||
|
||||
//
|
||||
// Look up the length of the string, reporting
|
||||
// errors if the string is invalid or the specified
|
||||
// length does not match the provided data.
|
||||
//
|
||||
func (str String) Length() (int, error) {
|
||||
if len(str) == 0 {
|
||||
// log
|
||||
@ -24,6 +29,10 @@ func (str String) Length() (int, error) {
|
||||
return length, nil
|
||||
}
|
||||
|
||||
//
|
||||
// Return the string data and any errors
|
||||
// encountered by Length.
|
||||
//
|
||||
func (str String) Data() (string, error) {
|
||||
length, err := str.Length()
|
||||
if err != nil {
|
||||
@ -39,6 +48,11 @@ func (str String) Data() (string, error) {
|
||||
return string(str[1:]), nil
|
||||
}
|
||||
|
||||
//
|
||||
// This function takes an unformatted go string
|
||||
// and returns a String and any errors encountered
|
||||
// during the encoding.
|
||||
//
|
||||
func ToI2PString(data string) (String, error) {
|
||||
data_len := len(data)
|
||||
if data_len >= 256 {
|
||||
@ -49,6 +63,10 @@ func ToI2PString(data string) (String, error) {
|
||||
return String(i2p_string), nil
|
||||
}
|
||||
|
||||
//
|
||||
// Read a string from a slice of bytes, returning
|
||||
// any extra data on the end of the slice.
|
||||
//
|
||||
func ReadString(data []byte) (String, []byte, error) {
|
||||
str := String(data)
|
||||
length, err := String(data).Length()
|
||||
|
Reference in New Issue
Block a user