lib

package
v0.0.0-...-b7062c8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2017 License: LGPL-3.0-or-later Imports: 22 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Address

func Address(pubKey []byte) int64

Address gets int64 EGGAS address from the public key

func AddressToString

func AddressToString(address int64) (ret string)

AddressToString converts int64 address to EGAAS address as XXXX-...-XXXX.

func BinMarshal

func BinMarshal(out *[]byte, v interface{}) (*[]byte, error)

BinMarshal converts v parameter to []byte slice.

func BinUnmarshal

func BinUnmarshal(out *[]byte, v interface{}) error

BinUnmarshal converts []byte slice which has been made with BinMarshal to v

func Bytes2Float

func Bytes2Float(bytes []byte) float64

Bytes2Float converts []byte to float64

func CBCDecrypt

func CBCDecrypt(key, ciphertext, iv []byte) ([]byte, error)

CBCDecrypt decrypts the text by using key. It uses CBC mode of AES.

func CBCEncrypt

func CBCEncrypt(key, text, iv []byte) ([]byte, error)

CBCEncrypt encrypts the text by using the key parameter. It uses CBC mode of AES.

func CRC64

func CRC64(input []byte) uint64

CRC64 returns crc64 sum

func CalculateMd5

func CalculateMd5(filePath string) ([]byte, error)

CalculateMd5 calculates MD5 hash of the file

func CheckECDSA

func CheckECDSA(public []byte, forSign string, signature []byte) (bool, error)

CheckECDSA checks if forSign has been signed with corresponding to public the private key

func CheckSum

func CheckSum(val []byte) int

CheckSum calculates the 0-9 check sum of []byte

func DecodeLenInt64

func DecodeLenInt64(data *[]byte) (int64, error)

DecodeLenInt64 gets int64 from []byte and shift the slice. The []byte should be encoded with EncodeLengthPlusInt64.

func DecodeLength

func DecodeLength(buf *[]byte) (ret int64, err error)

DecodeLength decodes []byte to int64 and shifts buf. Bytes must be encoded with EncodeLength function.

0x43 => 67
0x820400 => 1024
0x830f4240 => 1000000

func EGSMoney

func EGSMoney(money string) string

EGSMoney converts qEGS to EGS. For example, 123455000000000000000 => 123.455

func EncodeLenByte

func EncodeLenByte(out *[]byte, buf []byte) *[]byte

EncodeLenByte appends the length of the slice (EncodeLength) + the slice.

func EncodeLenInt64

func EncodeLenInt64(data *[]byte, x int64) *[]byte

EncodeLenInt64 appends int64 to []byte as uint8 + little-endian order of uint8.

65000 => [0x02, 0xe8, 0xfd]

func EncodeLength

func EncodeLength(length int64) []byte

EncodeLength encodes int64 number to []byte. If it is less than 128 then it returns []byte{length}. Otherwise, it returns (0x80 | len of int64) + int64 as BigEndian []byte

67 => 0x43
1024 => 0x820400
1000000 => 0x830f4240

func Escape

func Escape(data string) string

Escape deletes unaccessable characters

func EscapeForJSON

func EscapeForJSON(data string) string

EscapeForJSON replaces quote to slash and quote

func EscapeName

func EscapeName(name string) string

EscapeName deletes unaccessable characters for input name(s)

func FieldToBytes

func FieldToBytes(v interface{}, num int) []byte

FieldToBytes returns the value of n-th field of v as []byte

func FillLeft

func FillLeft(slice []byte) []byte

FillLeft fills the slice by zero at left if the size of the slice is less than 32.

func FillLeft64

func FillLeft64(slice []byte) []byte

FillLeft64 fills the slice by zero at left if the size of the slice is less than 32.

func Float2Bytes

func Float2Bytes(float float64) []byte

Float2Bytes converts float64 to []byte

func GenBytesKeys

func GenBytesKeys() ([]byte, []byte, error)

GenBytesKeys generates a random pair of ECDSA private and public binary keys.

func GenHexKeys

func GenHexKeys() (string, string, error)

GenHexKeys generates a random pair of ECDSA private and public hex keys.

func GetShared

func GetShared(public string) (string, string, error)

GetShared returns the combined key for the specified public key. If the text is encrypted with this key then it can be decrypted with the shared key made from private key and the returned public key (pub). All keys are hex strings.

func GetSharedHex

func GetSharedHex(private, public string) (string, error)

GetSharedHex generates a shared key from private and public key. All keys are hex string.

func GetSharedKey

func GetSharedKey(private, public []byte) (shared []byte, err error)

GetSharedKey creates and returns the shared key = private * public. public must be the public key from the different private key.

func HexToInt64

func HexToInt64(input string) (ret int64)

HexToInt64 converts hex int64 to int64

func IsValidAddress

func IsValidAddress(address string) bool

IsValidAddress checks if the specified address is EGAAS address.

func JSSignToBytes

func JSSignToBytes(in string) ([]byte, error)

JSSignToBytes converts hex signature which has got from the browser to []byte

func KeyToAddress

func KeyToAddress(pubKey []byte) string

KeyToAddress converts a public key to EGAAS address XXXX-...-XXXX.

func NumString

func NumString(in string) string

NumString insert spaces between each three digits. 7123456 => 7 123 456

func PKCS7Padding

func PKCS7Padding(src []byte, blockSize int) []byte

PKCS7Padding realizes PKCS#7 encoding which is described in RFC 5652.

func PKCS7UnPadding

func PKCS7UnPadding(src []byte) ([]byte, error)

PKCS7UnPadding realizes PKCS#7 decoding.

func PrivateToPublic

func PrivateToPublic(key []byte) []byte

PrivateToPublic returns the public key for the specified private key.

func PrivateToPublicHex

func PrivateToPublicHex(hexkey string) string

PrivateToPublicHex returns the hex public key for the specified hex private key.

func SharedDecrypt

func SharedDecrypt(private, ciphertext []byte) ([]byte, error)

SharedDecrypt decrypts the ciphertext by using private key.

func SharedEncrypt

func SharedEncrypt(public, text []byte) ([]byte, error)

SharedEncrypt creates a shared key and encrypts text. The first 32 characters are the created public key. The cipher text can be only decrypted with the original private key.

func SignECDSA

func SignECDSA(privateKey string, forSign string) (ret []byte, err error)

SignECDSA returns the signature of forSign made with privateKey.

func StringToAddress

func StringToAddress(address string) (result int64)

StringToAddress converts string EGAAS address to int64 address. The input address can be a positive or negative number, or EGAAS address in XXXX-...-XXXX format. Returns 0 when error occurs.

func StripTags

func StripTags(value string) string

StripTags replaces < and > to &lt; and &gt;

func Time32

func Time32() uint32

Time32 gets the current time in UNIX format.

func UintToBytes

func UintToBytes(val uint32) []byte

UintToBytes converts 32-byte value into [4]byte (BigEndian)

Types

type Update

type Update struct {
	Version string
	Hash    string
	Sign    string
	URL     string
}

Update contains version info parameters

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL