utils

package
v0.0.0-...-62a0fd1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

*

  • @Author: Bizzaro Francesco <d33pblue>
  • @Date: 2020-May-01
  • @Project: Proof of Evolution
  • @Filename: file_exists.go
  • @Last modified by: d33pblue
  • @Last modified time: 2020-May-09
  • @Copyright: 2020

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSignature

func CheckSignature(sign, hashed string, addr Addr) bool

Check the signature of some data from the hash and a public key.

func CompareHashes

func CompareHashes(h1, h2 string) bool

func CompareSlices

func CompareSlices(h1, h2 []byte) bool

func DownloadFile

func DownloadFile(url string, filepath string) error

Downloads a url to a local file, writing as it downloads and not loading the whole file into memory.

func ExportPrivateKeyAsPemStr

func ExportPrivateKeyAsPemStr(key Key) string

Returns the private key as string in pem format.

func ExportPublicKeyAsPemStr

func ExportPublicKeyAsPemStr(key Key) string

Returns the public key as string in pem format.

func ExportPublicKeyAsPemStr2

func ExportPublicKeyAsPemStr2(pubkey *rsa.PublicKey) string

Returns the public key as string in pem format.

func FetchDataFromUrl

func FetchDataFromUrl(url string) []byte

Returns the data at a url as []byte

func FileExists

func FileExists(filename string) bool

true <=> the file of [filename] path exists. That file must not be a folder.

func GetSignatureFromHash

func GetSignatureFromHash(hashed string, key Key) []byte

Signs data from the hash, using a private key.

func LoadPublicKeyFromPemStr

func LoadPublicKeyFromPemStr(pemStr []byte) (*rsa.PublicKey, error)

Create a public key from the bytes of a private key in pem format.

Types

type Addr

type Addr string // type for public key

func GetAddr

func GetAddr(key Key) Addr

Returns the public key (as Addr) from a Key.

func GetAddr2

func GetAddr2(key *rsa.PublicKey) Addr

Returns the public key (as Addr) from the private key.

type HashBuilder

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

HashBuilder can be used to collect data and obtain the hash of the total bytes.

func (*HashBuilder) Add

func (self *HashBuilder) Add(data interface{})

Adds some data to the HashBuilder. The data can be of any type and is read as []byte.

func (*HashBuilder) GetHash

func (self *HashBuilder) GetHash() []byte

Returns the hash of all the collected data of an HashBuilder.

type Key

type Key *rsa.PrivateKey // type for private key

func GenerateKey

func GenerateKey() (Key, error)

Generates a couple of public and private keys. The public key is stored inside; in order to extract it you can use GetAddr(key)

func LoadPrivateKeyFromPemStr

func LoadPrivateKeyFromPemStr(pemStr []byte) (Key, error)

Create a Key from the bytes of a private key in pem format.

type SignBuilder

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

Can be used as builder to store data and obtain a signature.

func (*SignBuilder) Add

func (self *SignBuilder) Add(data interface{})

Adds data to the SignBuilder. The data can be of any type and is read in []byte.

func (*SignBuilder) GetSignature

func (self *SignBuilder) GetSignature(key Key) []byte

Returns the signature of the collection of the submitted data of a SignBuilder.

Jump to

Keyboard shortcuts

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