Example #1
0
func TestAes(t *testing.T) {
	key, _ := ks.RandomBytes(32)
	c, _ := aes.NewCipher(key)
	a := ks.Aes{Cip: c}

	dest1, _ := a.Encrypt([]byte(hello))
	dest2, _ := a.Encrypt([]byte(hello))
	t.Logf("AES1: %s", dest1)
	t.Logf("AES2: %s", dest2)

	src, _ := a.Decrypt(dest1)
	if string(src) != hello {
		t.Errorf("val == %x, want %x", src, hello)
	}

}
Example #2
0
func TestHmac(t *testing.T) {
	key, _ := ks.RandomBytes(32)
	hm := ks.Hmac{
		Fn:  sha512.New,
		Key: key,
	}

	dest1 := hm.Sum([]byte(hello))
	dest2 := hm.Sum([]byte(hello))

	t.Logf("HMAC1(%d): %x", len(dest1), dest1)
	t.Logf("HMAC2(%d): %x", len(dest2), dest2)
	if !hm.Equal(dest1, dest2) {
		t.Errorf("HMAC FAILED!")
	}

}
Example #3
0
func TestDatabase(t *testing.T) {
	db, err := ko.Open("test")
	if err != nil {
		t.Errorf("error on open: %v", err)
	}
	db.Logger = kl.NewStdoutLogger(kl.DEBUG)

	key, _ := ku.RandomBytes(32)
	cip, _ := aes.NewCipher(key)
	aes := ku.Aes{Cip: cip}

	ds := ks.DatabaseStore{Db: db, Aes: &aes}

	if err = db.Migrate(); err != nil {
		t.Errorf("error on migrate: %v", err)
	}

	test_store(t, &ds)
}
Example #4
0
func TestOthers(t *testing.T) {
	t.Logf("UUID: %s", ks.Uuid())

	if buf, err := ks.RandomBytes(16); err == nil {
		t.Logf("Random bytes %v", buf)
		bs := ks.ToBase64(buf)
		t.Logf("Base encode %s", bs)
		if buf1, err := ks.FromBase64(bs); err == nil && ks.Equal(buf, buf1) {
			t.Logf("Base64 Decode: %s", buf1)
		} else {
			t.Errorf("Decode base64 error! %v", err)
		}
	} else {
		t.Errorf("Random bytes error! %v", err)
	}

	if err := ks.Shell("/usr/bin/uname", "-a"); err != nil {
		t.Errorf("Run script error! %v", err)
	}
}