Skip to content

Commit

Permalink
Doc: Add godoc in crypto and sign packages.
Browse files Browse the repository at this point in the history
Refactor: Move sign into crypto folder.

Refers to #119 and #40
  • Loading branch information
Jose Luis Lucas committed Jun 14, 2019
1 parent 8e1179b commit 6f3295b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion crypto/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
limitations under the License.
*/

// Package crypto implements key generators.
package crypto

import (
Expand All @@ -23,8 +24,8 @@ import (
"golang.org/x/crypto/ed25519"
)

// NewEd25519SignerKeysFile generates a new private/public signer key.
func NewEd25519SignerKeysFile(path string) (string, string, error) {
// Generate a new private/public signer keys for QED server
outPriv := path + "/qed_ed25519"
outPub := outPriv + ".pub"

Expand Down
7 changes: 7 additions & 0 deletions sign/sign.go → crypto/sign/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
limitations under the License.
*/

// Package sign implements funcionality to create signers, which are
// able to sign messages and verify signed messages.
package sign

import (
Expand All @@ -25,6 +27,8 @@ import (
"golang.org/x/crypto/ed25519"
)

// Signer is the interface implemented by any value that has Sign and Verify methods.
// Signers are able to sign messages and verify them using a signature.
type Signer interface {
Sign(message []byte) ([]byte, error)
Verify(message, sig []byte) (bool, error)
Expand All @@ -35,6 +39,7 @@ type Ed25519Signer struct {
publicKey ed25519.PublicKey
}

// NewEd25519Signer creates an ed25519 signer from scratch.
func NewEd25519Signer() Signer {

publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)
Expand All @@ -49,6 +54,8 @@ func NewEd25519Signer() Signer {

}

// NewEd25519SignerFromFile creates an ed25519 signer using existing private and
// public keys. It also checks that keys are usable.
func NewEd25519SignerFromFile(privateKeyPath string) (Signer, error) {

privateKeyBytes, err := ioutil.ReadFile(privateKeyPath)
Expand Down
9 changes: 5 additions & 4 deletions sign/sign_test.go → crypto/sign/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"testing"

assert "github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
)

func testSign(t *testing.T, signer Signer) {
Expand All @@ -30,16 +30,17 @@ func testSign(t *testing.T, signer Signer) {
sig, _ := signer.Sign(message)
result, _ := signer.Verify(message, sig)

assert.True(t, result, "Must be verified")
require.True(t, result, "Must be verified")

}

func TestEdSign(t *testing.T) { testSign(t, NewEd25519Signer()) }

func syncBenchmark(b *testing.B, signer Signer, iterations int) {

b.N = iterations
for i := 0; i < b.N; i++ {
signer.Sign([]byte(fmt.Sprintf("send reinforcements, we're going to advance %d", b.N)))
_, _ = signer.Sign([]byte(fmt.Sprintf("send reinforcements, we're going to advance %d", b.N)))
}

}
Expand All @@ -54,7 +55,7 @@ func asyncBenchmark(b *testing.B, signer Signer, numRoutines, iterations int) {
for {
select {
case msg := <-data:
signer.Sign([]byte(fmt.Sprintf("send reinforcements, we're going to advance %s", msg)))
_, _ = signer.Sign([]byte(fmt.Sprintf("send reinforcements, we're going to advance %s", msg)))
case <-close:
return
}
Expand Down
2 changes: 1 addition & 1 deletion server/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"fmt"
"time"

"github.com/bbva/qed/crypto/sign"
"github.com/bbva/qed/gossip"
"github.com/bbva/qed/log"
"github.com/bbva/qed/metrics"
"github.com/bbva/qed/protocol"
"github.com/bbva/qed/sign"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ import (

"github.com/bbva/qed/api/apihttp"
"github.com/bbva/qed/api/mgmthttp"
"github.com/bbva/qed/crypto/sign"
"github.com/bbva/qed/gossip"
"github.com/bbva/qed/log"
"github.com/bbva/qed/metrics"
"github.com/bbva/qed/protocol"
"github.com/bbva/qed/raftwal"
"github.com/bbva/qed/sign"
"github.com/bbva/qed/storage/rocks"
)

Expand Down

0 comments on commit 6f3295b

Please sign in to comment.