util

package module
v0.0.0-...-cf0af9d Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2018 License: MIT Imports: 27 Imported by: 3

README

"# util"

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeserializeGob

func DeserializeGob(a interface{}, bb []byte) error

func DigiPrint

func DigiPrint(s string) string

func GenSalt

func GenSalt(size int) []byte

func GenerateCert

func GenerateCert(org, hosts string, bits int) (key, cert []byte, err error)

comma separted hosts / IP

func Hash

func Hash(bb []byte, h hash.Hash) []byte

func Lfmt

func Lfmt(n int) string

func NewCommentReader

func NewCommentReader(r io.Reader, char rune) io.Reader

func SaltedHash256

func SaltedHash256(data, salt []byte) (hash, outSalt []byte)

func SaltedHash512

func SaltedHash512(data, salt []byte) (hash, outSalt []byte)

func SerializeGob

func SerializeGob(a interface{}) ([]byte, error)

func Sha256

func Sha256(bb []byte) []byte

func Sha512

func Sha512(bb []byte) []byte

func StrFieldsQuoted

func StrFieldsQuoted(bQuotedOnly bool) func(r rune) bool

func ToHex

func ToHex(bb []byte) string

func WithCtxKVMap

func WithCtxKVMap(ctx context.Context, m map[interface{}]interface{}) context.Context

func YielderArr

func YielderArr(data []interface{}) func() (interface{}, bool)

Types

type CallInfo

type CallInfo struct {
	// contains filtered or unexported fields
}

callInfo bundles the info about the call environment when a logging statement occured.

func RetrieveCallInfo

func RetrieveCallInfo(n int) *CallInfo

func RetrieveCallInfos

func RetrieveCallInfos(ns int) (calls []*CallInfo)

retrieveCallInfo

func (*CallInfo) ShortFormat

func (ci *CallInfo) ShortFormat() string

shortFormat returns a string representation in a short variant.

func (*CallInfo) VerboseFormat

func (ci *CallInfo) VerboseFormat() string

verboseFormat returns a string representation in a more verbose variant.

type CommentReader

type CommentReader struct {
	CommentChar rune
	// contains filtered or unexported fields
}

func (*CommentReader) Read

func (this *CommentReader) Read(p []byte) (n int, err error)

type Params

type Params struct {
	// contains filtered or unexported fields
}

func ReadPropertyFile

func ReadPropertyFile(fpath string) (o *Params, err error)

func ReadPropertyParams

func ReadPropertyParams(rdr io.Reader) (o *Params, err error)

key / value separated by '='

func (Params) Env

func (this Params) Env(k string) string

func (Params) For

func (this Params) For(prefix string, cb func(k, v string))

func (Params) Get

func (this Params) Get(s, defval string) string

func (Params) GetFloat64

func (this Params) GetFloat64(s string, defval float64) float64

func (Params) GetInt

func (this Params) GetInt(s string, defval int) int

func (*Params) Merge

func (this *Params) Merge(a *Params)

type PrivKey

type PrivKey rsa.PrivateKey
Example
package main

import (
	"fmt"

	"github.com/noypi/util"
)

func main() {
	// sender's keys
	privkSender, _ := util.GenPrivKey(2048)
	pubkSender := privkSender.PubKey()

	// receiver's keys
	privkRecvr, _ := util.GenPrivKey(2048)
	pubkRecvr := privkRecvr.PubKey()

	const message = "hello youtube"

	// encrypt message
	bbCipher, _ := pubkRecvr.Encrypt([]byte(message))
	signatureSender, _ := privkSender.Sign(bbCipher)

	// sending [cipher, signature]

	// verify / decrypt message
	bbPlain, _ := privkRecvr.Decrypt(bbCipher)
	bValid := (nil == pubkSender.Verify(bbCipher, signatureSender))

	if bValid {
		fmt.Println(string(bbPlain))
	}

}
Output:

hello youtube

func GenPrivKey

func GenPrivKey(bits int) (*PrivKey, error)

func (*PrivKey) Decrypt

func (this *PrivKey) Decrypt(bb []byte) ([]byte, error)

func (*PrivKey) Marshal

func (this *PrivKey) Marshal() []byte

func (*PrivKey) MarshalPem

func (this *PrivKey) MarshalPem() []byte

func (*PrivKey) PubKey

func (this *PrivKey) PubKey() *PubKey

func (*PrivKey) Sign

func (mypriv *PrivKey) Sign(bb []byte) (signature []byte, err error)

func (*PrivKey) SignMessage

func (mypriv *PrivKey) SignMessage(bb []byte) (msg *SignedMessage, err error)

func (*PrivKey) SignMessageAndMarshal

func (mypriv *PrivKey) SignMessageAndMarshal(bb []byte) ([]byte, error)

type PubKey

type PubKey rsa.PublicKey

func ParsePublickey

func ParsePublickey(bb []byte) (*PubKey, error)

func ParsePublickeyPem

func ParsePublickeyPem(bbPem []byte) (*PubKey, error)

func (*PubKey) DigiPrint

func (hisPubK *PubKey) DigiPrint() string

func (*PubKey) Encrypt

func (this *PubKey) Encrypt(bb []byte) ([]byte, error)

func (*PubKey) Marshal

func (this *PubKey) Marshal() (bbPub []byte, err error)

func (*PubKey) MarshalPem

func (this *PubKey) MarshalPem() ([]byte, error)

func (*PubKey) Verify

func (hisPubK *PubKey) Verify(msg, signature []byte) error

func (*PubKey) VerifyMessage

func (hisPubK *PubKey) VerifyMessage(msg *SignedMessage) (err error)

func (*PubKey) VerifyMessageRaw

func (hisPubK *PubKey) VerifyMessageRaw(bb []byte) (msg []byte, err error)

type SignedMessage

type SignedMessage struct {
	Message   []byte
	Signature []byte
}

type Stack

type Stack list.List

func NewStack

func NewStack() *Stack

func (*Stack) Len

func (this *Stack) Len() int

func (*Stack) Pop

func (this *Stack) Pop() interface{}

func (*Stack) Push

func (this *Stack) Push(e interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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