mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-07-04 13:32:52 -04:00
some godoc
This commit is contained in:
@ -34,6 +34,11 @@ func (certificate Certificate) Type() byte {
|
|||||||
return certificate[0]
|
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) {
|
func (certificate Certificate) Length() (int, error) {
|
||||||
if len(certificate) < 3 {
|
if len(certificate) < 3 {
|
||||||
// log
|
// log
|
||||||
@ -52,6 +57,10 @@ func (certificate Certificate) Length() (int, error) {
|
|||||||
return length, nil
|
return length, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the certificate data and any errors
|
||||||
|
// encountered by Length.
|
||||||
|
//
|
||||||
func (certificate Certificate) Data() ([]byte, error) {
|
func (certificate Certificate) Data() ([]byte, error) {
|
||||||
length, err := certificate.Length()
|
length, err := certificate.Length()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -81,6 +90,10 @@ func (certificate Certificate) SignatureSize() int {
|
|||||||
return sizes[int(certificate.Type())]
|
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) {
|
func ReadCertificate(data []byte) (Certificate, []byte, error) {
|
||||||
certificate := Certificate(data)
|
certificate := Certificate(data)
|
||||||
length, err := certificate.Length()
|
length, err := certificate.Length()
|
||||||
|
@ -6,6 +6,13 @@ import (
|
|||||||
|
|
||||||
type Date [8]byte
|
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 {
|
func (date Date) Time() time.Time {
|
||||||
seconds := Integer(date[:])
|
seconds := Integer(date[:])
|
||||||
return time.Unix(0, int64(seconds*1000000))
|
return time.Unix(0, int64(seconds*1000000))
|
||||||
|
@ -4,6 +4,11 @@ import (
|
|||||||
"encoding/binary"
|
"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 {
|
func Integer(number []byte) int {
|
||||||
num_len := len(number)
|
num_len := len(number)
|
||||||
if num_len < 8 {
|
if num_len < 8 {
|
||||||
|
@ -6,6 +6,11 @@ import (
|
|||||||
|
|
||||||
type String []byte
|
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) {
|
func (str String) Length() (int, error) {
|
||||||
if len(str) == 0 {
|
if len(str) == 0 {
|
||||||
// log
|
// log
|
||||||
@ -24,6 +29,10 @@ func (str String) Length() (int, error) {
|
|||||||
return length, nil
|
return length, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the string data and any errors
|
||||||
|
// encountered by Length.
|
||||||
|
//
|
||||||
func (str String) Data() (string, error) {
|
func (str String) Data() (string, error) {
|
||||||
length, err := str.Length()
|
length, err := str.Length()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -39,6 +48,11 @@ func (str String) Data() (string, error) {
|
|||||||
return string(str[1:]), nil
|
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) {
|
func ToI2PString(data string) (String, error) {
|
||||||
data_len := len(data)
|
data_len := len(data)
|
||||||
if data_len >= 256 {
|
if data_len >= 256 {
|
||||||
@ -49,6 +63,10 @@ func ToI2PString(data string) (String, error) {
|
|||||||
return String(i2p_string), nil
|
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) {
|
func ReadString(data []byte) (String, []byte, error) {
|
||||||
str := String(data)
|
str := String(data)
|
||||||
length, err := String(data).Length()
|
length, err := String(data).Length()
|
||||||
|
Reference in New Issue
Block a user