Skip to content

Commit

Permalink
[panthalassa] added cid utils export
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Lenz committed Apr 22, 2018
1 parent a65f2f5 commit d2ca321
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crypto/cid.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

//Check if CID is valid
func isValidCid(id string) bool {
func IsValidCid(id string) bool {

_, err := cid.Decode(id)

Expand Down
12 changes: 6 additions & 6 deletions crypto/cid_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package crypto

import (
"testing"
"github.com/stretchr/testify/require"
"testing"
)

func TestCIDSha256(t *testing.T) {
Expand All @@ -17,8 +17,8 @@ func TestCIDSha512(t *testing.T) {
require.Equal(t, "UAVUUQEG8zpe5V7XbE9ZuG_0-q4q0ujKrksvGUoJTCs2fTjXSUvfOE6Z4f9ePhYante_RzbqCZT5RADYOegO_Yiz8WJo=", cid)
}

func TestIsValidCid(t *testing.T) {
require.True(t, isValidCid("mAVUWIDAwU3dua7xpbnFfMuJGB3ydE8z6o/Oz8+bihw3lVhT1"))
require.True(t, isValidCid("UAVUUQEG8zpe5V7XbE9ZuG_0-q4q0ujKrksvGUoJTCs2fTjXSUvfOE6Z4f9ePhYante_RzbqCZT5RADYOegO_Yiz8WJo="))
require.False(t, isValidCid("I should be invalid"))
}
func TestIsValidCid(t *testing.T) {
require.True(t, IsValidCid("mAVUWIDAwU3dua7xpbnFfMuJGB3ydE8z6o/Oz8+bihw3lVhT1"))
require.True(t, IsValidCid("UAVUUQEG8zpe5V7XbE9ZuG_0-q4q0ujKrksvGUoJTCs2fTjXSUvfOE6Z4f9ePhYante_RzbqCZT5RADYOegO_Yiz8WJo="))
require.False(t, IsValidCid("I should be invalid"))
}
17 changes: 17 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,20 @@ func NewAccountKeysFromMnemonic(mnemonic, pw, pwConfirm string) (string, error)
km := keyManager.CreateFromKeyStore(ks)
return km.Export(pw, pwConfirm)
}

//Get the CID of a value with
//sha3 512 as a base64 string
func CIDSha512(value string) (string, error) {
return crypto.CIDSha512(value)
}

//Get the CID of a value with
//sha3 256 as a base64 string
func CIDSha256(value string) (string, error) {
return crypto.CIDSha256(value)
}

//Check if CID is valid
func IsValidCID(cid string) bool {
return crypto.IsValidCid(cid)
}

0 comments on commit d2ca321

Please sign in to comment.