storj/examples/paths/main.go

69 lines
1.6 KiB
Go
Raw Normal View History

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"encoding/hex"
"fmt"
"os"
"github.com/tyler-smith/go-bip39"
"storj.io/storj/pkg/paths"
)
const mnemonic = "style inspire blade just ignore expose midnight maze " +
"boring code burst host giraffe face parent basic ritual distance " +
"trophy join relief hidden fine yard"
var path = paths.New("fold1/fold2/fold3/file.txt")
func main() {
err := Main()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}
// Main is the exported CLI executable function
func Main() error {
fmt.Println("mnemonic:", mnemonic)
seed, err := bip39.NewSeedWithErrorChecking(mnemonic, "")
if err != nil {
return err
}
fmt.Printf("root key (%d bytes): %s\n", len(seed),
hex.EncodeToString(seed))
encryptedPath, err := path.Encrypt(seed)
if err != nil {
return err
}
fmt.Println("path to encrypt:", path)
fmt.Println("encrypted path: ", encryptedPath)
decryptedPath, err := encryptedPath.Decrypt(seed)
if err != nil {
return err
}
fmt.Println("decrypted path: ", decryptedPath)
sharedPath := encryptedPath[2:]
fmt.Println("shared path: ", encryptedPath[2:])
derivedKey, err := decryptedPath.DeriveKey(seed, 2)
if err != nil {
return err
}
fmt.Printf("derived key (%d bytes): %s\n", len(derivedKey),
hex.EncodeToString(derivedKey))
decryptedPath, err = sharedPath.Decrypt(derivedKey)
if err != nil {
return err
}
fmt.Println("decrypted path: ", decryptedPath)
Mutex/nsclient- WIP (#104) * working on put request for nsclient * working on put request for nsclient * netstate put * netstate put * wip testing client * wip - testing client and working through some errors * wip - testing client and working through some errors * put request works * put request works for client * get request working * get request working * get request working-minor edit * get request working-minor edit * list request works * list request works * working through delete error * working through delete error * fixed exp client, still working through delete error * fixed exp client, still working through delete error * delete works; fixed formatting issues * delete works; fixed formatting issues * deleted comment * deleted comment * resolving merge conflicts * resolving merge conflict * fixing merge conflict * implemented and modified kayloyans paths file * working on testing * added test for path_test.go * fixed string, read through netstate test * deleted env variables * initial commit for mocking out grpc client- got it working * mocked grpc client * mock put passed test * 2 tests pass for PUT with mock * put requests test pass, wip- want mini review * get tests pass mock * list test working * initial commit for list test * all list req. working, starting on delete tests * delete tests passed * cleaned up tests * resolved merge conflicts * resolved merge conflicts * fixed linter errors * fixed error found in travis * initial commit for fixes from PR comments * fixed pr comments and linting * added error handling for api creds, and rebased * fixes from dennis comments * fixed pr with dennis suggestioon * added copyrights to files * fixed casing per dennis great comment * fixed travis complaint on sprintf
2018-07-19 23:57:22 +01:00
// implement Bytes() function
var pathBytes = path.Bytes()
fmt.Println("path in Bytes is: ", pathBytes)
return nil
}