github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/libkb/per_user_key_test.go (about) 1 package libkb 2 3 import ( 4 "encoding/hex" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestNewPerUserKeySecretBox(t *testing.T) { 11 // Test a roundtrip 12 13 seed := PerUserKeySeed([32]byte{1, 2, 2}) 14 seed[31] = 9 15 key := NaclSecretBoxKey([32]byte{5, 6, 7, 8}) 16 17 // seal 18 secretbox, err := newPerUserKeyPrev(seed, key) 19 require.NoError(t, err) 20 t.Logf("seed: %v", hex.EncodeToString(seed[:])) 21 t.Logf("key : %v", hex.EncodeToString(key[:])) 22 t.Logf("sb : %v", secretbox) 23 24 // open 25 seedOut, err := openPerUserKeyPrev(secretbox, key) 26 require.NoError(t, err) 27 t.Logf("seed expected: %T %v", seed, seed) 28 t.Logf("seed result: %T %v", seedOut, seedOut) 29 require.Equal(t, seed, seedOut) 30 } 31 32 func TestNewPerUserKeySecretBox2(t *testing.T) { 33 // Test opening a canned one 34 35 expectedSeed, err := hex.DecodeString("7c13fbe503aa2f79970e43eeb832820cfbf67ee4298ae5345ffe19cc1048bdee") 36 require.NoError(t, err) 37 key1, err := hex.DecodeString("29e48abe7de0da83023ee5741c2a8959624325f2e6b8ed2c96caf676d05d7cda") 38 key := MakeByte32(key1) 39 require.NoError(t, err) 40 41 sb := "kwG4BAQEAAAAAAAAAAAAAAAAAAAAAAAAAAAA2gAwWiGRZRwucAYHVQ4xJAX9Zn7F5WfnjOmjBd3n\nxkpS8xUFQhjmQRXAfUadTNqY5TU7\n" 42 43 seed, err := openPerUserKeyPrev(PerUserKeyPrev(sb), key) 44 require.NoError(t, err) 45 require.Equal(t, PerUserKeySeed(MakeByte32(expectedSeed)), seed) 46 }