Browse Source

crypto: Rename last traces of go-crypto (#1786)

Follow-up to #1782
pull/1797/head
Alexander Simmerl 6 years ago
committed by Anton Kaliaev
parent
commit
3e1baf68f8
6 changed files with 40 additions and 43 deletions
  1. +3
    -3
      crypto/README.md
  2. +1
    -1
      crypto/amino.go
  3. +32
    -35
      crypto/doc.go
  4. +1
    -1
      crypto/priv_key_test.go
  5. +1
    -1
      docs/spec/p2p/peer.md
  6. +2
    -2
      types/protobuf.go

+ 3
- 3
crypto/README.md View File

@ -1,6 +1,6 @@
# go-crypto
# crypto
go-crypto is the cryptographic package adapted for Tendermint's uses
crypto is the cryptographic package adapted for Tendermint's uses
## Importing it
`import "github.com/tendermint/tendermint/crypto"`
@ -11,7 +11,7 @@ For Binary encoding, please refer to the [Tendermint encoding spec](https://gith
## JSON Encoding
go-crypto `.Bytes()` uses Amino:binary encoding, but Amino:JSON is also supported.
crypto `.Bytes()` uses Amino:binary encoding, but Amino:JSON is also supported.
```go
Example Amino:JSON encodings:


+ 1
- 1
crypto/amino.go View File

@ -15,7 +15,7 @@ func init() {
RegisterAmino(cdc)
}
// RegisterAmino registers all go-crypto related types in the given (amino) codec.
// RegisterAmino registers all crypto related types in the given (amino) codec.
func RegisterAmino(cdc *amino.Codec) {
cdc.RegisterInterface((*PubKey)(nil), nil)
cdc.RegisterConcrete(PubKeyEd25519{},


+ 32
- 35
crypto/doc.go View File

@ -1,48 +1,45 @@
/*
go-crypto is a customized/convenience cryptography package
for supporting Tendermint.
// crypto is a customized/convenience cryptography package for supporting
// Tendermint.
It wraps select functionality of equivalent functions in the
Go standard library, for easy usage with our libraries.
// It wraps select functionality of equivalent functions in the
// Go standard library, for easy usage with our libraries.
Keys:
// Keys:
All key generation functions return an instance of the PrivKey interface
which implements methods
// All key generation functions return an instance of the PrivKey interface
// which implements methods
AssertIsPrivKeyInner()
Bytes() []byte
Sign(msg []byte) Signature
PubKey() PubKey
Equals(PrivKey) bool
Wrap() PrivKey
// AssertIsPrivKeyInner()
// Bytes() []byte
// Sign(msg []byte) Signature
// PubKey() PubKey
// Equals(PrivKey) bool
// Wrap() PrivKey
From the above method we can:
a) Retrieve the public key if needed
// From the above method we can:
// a) Retrieve the public key if needed
pubKey := key.PubKey()
// pubKey := key.PubKey()
For example:
privKey, err := crypto.GenPrivKeyEd25519()
if err != nil {
...
}
pubKey := privKey.PubKey()
...
// And then you can use the private and public key
doSomething(privKey, pubKey)
// For example:
// privKey, err := crypto.GenPrivKeyEd25519()
// if err != nil {
// ...
// }
// pubKey := privKey.PubKey()
// ...
// // And then you can use the private and public key
// doSomething(privKey, pubKey)
// We also provide hashing wrappers around algorithms:
We also provide hashing wrappers around algorithms:
// Sha256
// sum := crypto.Sha256([]byte("This is Tendermint"))
// fmt.Printf("%x\n", sum)
Sha256
sum := crypto.Sha256([]byte("This is Tendermint"))
fmt.Printf("%x\n", sum)
Ripemd160
sum := crypto.Ripemd160([]byte("This is consensus"))
fmt.Printf("%x\n", sum)
*/
// Ripemd160
// sum := crypto.Ripemd160([]byte("This is consensus"))
// fmt.Printf("%x\n", sum)
package crypto
// TODO: Add more docs in here

+ 1
- 1
crypto/priv_key_test.go View File

@ -28,7 +28,7 @@ func TestReadPrivKey(t *testing.T) {
// garbage in, garbage out
garbage := []byte("hjgewugfbiewgofwgewr")
XXX This test wants to register BadKey globally to go-crypto,
XXX This test wants to register BadKey globally to crypto,
but we don't want to support that.
_, err := PrivKeyFromBytes(garbage)
require.Error(err)


+ 1
- 1
docs/spec/p2p/peer.md View File

@ -7,7 +7,7 @@ For details on peer discovery, see the [peer exchange (PEX) reactor doc](https:/
## Peer Identity
Tendermint peers are expected to maintain long-term persistent identities in the form of a public key.
Each peer has an ID defined as `peer.ID == peer.PubKey.Address()`, where `Address` uses the scheme defined in go-crypto.
Each peer has an ID defined as `peer.ID == peer.PubKey.Address()`, where `Address` uses the scheme defined in `crypto` package.
A single peer ID can have multiple IP addresses associated with it, but a node
will only ever connect to one at a time.


+ 2
- 2
types/protobuf.go View File

@ -58,7 +58,7 @@ func (tm2pb) Validator(val *Validator) abci.Validator {
}
// XXX: panics on nil or unknown pubkey type
// TODO: add cases when new pubkey types are added to go-crypto
// TODO: add cases when new pubkey types are added to crypto
func (tm2pb) PubKey(pubKey crypto.PubKey) abci.PubKey {
switch pk := pubKey.(type) {
case crypto.PubKeyEd25519:
@ -153,7 +153,7 @@ var PB2TM = pb2tm{}
type pb2tm struct{}
func (pb2tm) PubKey(pubKey abci.PubKey) (crypto.PubKey, error) {
// TODO: define these in go-crypto and use them
// TODO: define these in crypto and use them
sizeEd := 32
sizeSecp := 33
switch pubKey.Type {


Loading…
Cancel
Save