Index: testservices/identityservice/util.go |
=== added file 'testservices/identityservice/util.go' |
--- testservices/identityservice/util.go 1970-01-01 00:00:00 +0000 |
+++ testservices/identityservice/util.go 2012-11-11 15:29:52 +0000 |
@@ -0,0 +1,31 @@ |
+package identityservice |
+ |
+import ( |
+ "crypto/rand" |
+ "encoding/hex" |
+ "fmt" |
+) |
+ |
+type UserInfo struct { |
+ secret string |
+ token string |
+} |
+ |
+// Generate a bit of random hex data for |
+func randomHexToken() string { |
+ raw_bytes := make([]byte, 16) |
rog
2012/11/26 12:51:38
rawBytes
or just "raw", or "buf"?
the latter is p
|
+ n, err := rand.Read(raw_bytes) |
rog
2012/11/26 12:51:38
io.ReadFull
|
+ if n != 16 || err != nil { |
rog
2012/11/26 12:51:38
if err != nil {
|
+ panic(fmt.Sprintf( |
+ "Could not read 16 random bytes safely: %d %s", |
+ n, err.Error())) |
+ } |
rog
2012/11/26 12:51:38
return fmt.Sprintf("%x", ...)
|
+ hex_bytes := make([]byte, 32) |
+ n = hex.Encode(hex_bytes, raw_bytes) |
+ if n != 32 || err != nil { |
+ panic(fmt.Sprintf( |
+ "Failed to Encode 32 bytes: %d %s", |
+ n, err.Error())) |
+ } |
+ return string(hex_bytes) |
+} |