sdk

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

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

Go to latest
Published: May 7, 2021 License: MIT Imports: 12 Imported by: 1

README

Go Report Card Build Status

Avocado SDK

Avocado SDK encrypt with RSA keys a values ​​to be store in the key-value store.

Supported

How to

Install

To start using Avocado SDK, install Go and run go get command as a follow

go get github.com/lorenzodisidoro/avocado-sdk

Use

To use SDK methods import in your GO file

import sdk "github.com/lorenzodisidoro/avocado-sdk"
Storage configuration

Create the storage configuration

BBolt
storage := &sdk.StorageClient{
    Bbolt: &sdk.BboltStorage{
        SotoragePath: "./mybolt.db",
        BucketName:   "test",
    },
}
Redis
storage := &StorageClient{
	Redis: &RedisStorage{
		Address:  "localhost:6379",
		Password: "", // no password set
		DB:       0,  // use default DB
	},
}
Create a new instance

Create a new SDK instance

avocado := sdk.Avocado{}
err := avocado.New(storage)
if err != nil {
    return err
}
Methods
Encrypt and save value

Value can be encrypted and stored using the following methods

encryptedValue, err := avocado.EecryptAndStoreValue([]byte("key1"), []byte("my value"), "/path/to/my_public_key.pem")
Find and decrypt value
decryptedValue, err := avocado.FindAndDecryptValueBy([]byte("key1"), "/path/to/my_private_key.pem")
Get all keys
keys, err := avocado.GetAllKeys()
Remove a key
err := avocado.Delete([]byte("key1"))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorFilePathNotProvided    = errors.New("file path not provided")
	ErrorValueNotProvided       = errors.New("value not provided")
	ErrorKeyNotProvided         = errors.New("value label not provided")
	ErrorEncryptedValueNotFound = errors.New("encrypted value not found")
)

Error messages

Functions

This section is empty.

Types

type Avocado

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

Avocado defines RSA keys and storage configurations

func (*Avocado) Delete

func (a *Avocado) Delete(key []byte) error

Delete remove a key @return error

func (*Avocado) EecryptAndStoreValue

func (a *Avocado) EecryptAndStoreValue(key, value []byte, publicKeyPath string) ([]byte, error)

EecryptAndStoreValue encrypt and store value using RSA public key @param key and value in byte format @return encrypted value bytes

func (*Avocado) FindAndDecryptValueBy

func (a *Avocado) FindAndDecryptValueBy(key []byte, privateKeyPath string) ([]byte, error)

FindAndDecryptValueBy find and decrypt value method read private key from file @param key in byte format @return decrypted value bytes

func (*Avocado) GetAllKeys

func (a *Avocado) GetAllKeys() ([][]byte, error)

GetAllKeys return all keys @return all keys

func (*Avocado) New

func (a *Avocado) New(config *StorageClient) error

New constructs a key value to store

type BboltStorage

type BboltStorage struct {
	SotoragePath string
	BucketName   string
	// contains filtered or unexported fields
}

BboltStorage defines bbolt client settings

type RedisStorage

type RedisStorage struct {
	Address  string
	Password string
	DB       int
	// contains filtered or unexported fields
}

RedisStorage defines redis client settings

type StorageClient

type StorageClient struct {
	Bbolt *BboltStorage
	Redis *RedisStorage
}

StorageClient defines key value storage client type

func (*StorageClient) New

func (sc *StorageClient) New() error

New create a new instance of storage client

Jump to

Keyboard shortcuts

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