Commit e47fd220 authored by Jordan Sissel's avatar Jordan Sissel

- shuffle things around to make 'go install lumberjack' and 'go install

keygen' work
parent 4570be28
build:
sh build.sh
clean:
rm -fr pkg bin
make -C ../ build/lib/libsodium.so build/lib/libzmq.so
make -C ../ build/include/sodium/sodium.h build/include/zmq.h
export CGO_CFLAGS=-I$PWD/../build/include
export CGO_LDFLAGS=-L$PWD/../build/lib
go get github.com/alecthomas/gozmq
#go install github.com/alecthomas/gozmq
#go install sodium
echo "Building lumberjack"
go install lumberjack
echo "Building keygen"
go install keygen
package main
import (
"sodium"
"os"
"log"
"flag"
)
var output = flag.String("output", "nacl", "The output prefix to use. This will generate 'nacl.priv' and 'nacl.pub' for the private and public keys, respectively, where 'nacl' is the flag value you set.")
func main() {
flag.Parse()
pk, sk := sodium.CryptoBoxKeypair()
write(*output + ".pub", pk[:])
write(*output + ".priv", sk[:])
} /* main */
func write(path string, value []byte) {
file, err := os.OpenFile(path, os.O_WRONLY | os.O_CREATE, 0600)
if err != nil {
log.Fatalf("Failed to open file (%s) for writing: %s\n",
path, err)
return
}
n, err := file.Write(value)
if err != nil {
log.Fatalf("Failed to write to file (%s): %s\n",
path, err)
return
}
if n < len(value) {
log.Fatalf("Failed write to file (%s). Wrote %d of %d bytes.\n",
path, n, len(value))
return
}
err = file.Close()
if err != nil {
log.Fatalf("Failure closing file (%s): %s\n", path, err);
return
}
}
package lumberjack
package liblumberjack
type FileEvent struct {
Source *string `json:"source,omitempty"`
......
package lumberjack
package liblumberjack
import (
"os" // for File and friends
......
package lumberjack
package liblumberjack
import (
"time"
......
package lumberjack
package liblumberjack
import (
"log"
......
package lumberjack
package liblumberjack
import (
"time"
......
......@@ -2,7 +2,7 @@ package main
import (
"log"
"lumberjack"
lumberjack "liblumberjack"
"os"
"time"
"flag"
......
package sodium
// #include <sodium.h>
// #cgo LDFLAGS: -lsodium
import "C"
import "fmt"
import "unsafe"
const PUBLICKEYBYTES int = 32
const SECRETKEYBYTES int = 32
func CryptoBoxKeypair() (pk [SECRETKEYBYTES]byte, sk [PUBLICKEYBYTES]byte) {
// From golang.org/cmd/cgo
// """ In C, a function argument written as a fixed size array actually
// requires a pointer to the first element of the array. C compilers are
// aware of this calling convention and adjust the call accordingly, but
// Go cannot. In Go, you must pass the pointer to the first element
// explicitly: C.f(&x[0]). """
C.crypto_box_curve25519xsalsa20poly1305_ref_keypair(
(*C.uchar)(unsafe.Pointer(&pk[0])),
(*C.uchar)(unsafe.Pointer(&sk[0])))
return
}
func CryptoBox(nonce []byte, plaintext string) {
}
func CryptoOpen(nonce []byte, ciphertext string) {
}
func main() {
sk, pk := CryptoBoxKeypair()
fmt.Printf("sk: %v\n", sk)
fmt.Printf("pk: %v\n", pk)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment