-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add-space-after-colon
- Loading branch information
Showing
17 changed files
with
469 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package debug | ||
|
||
var ( | ||
DebugCap uint32 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package debug | ||
|
||
import ( | ||
"fmt" | ||
"encoding/binary" | ||
|
||
"git.grassecon.net/urdt/ussd/common" | ||
"git.defalsify.org/vise.git/db" | ||
) | ||
|
||
var ( | ||
dbTypStr map[common.DataTyp]string = make(map[common.DataTyp]string) | ||
) | ||
|
||
type KeyInfo struct { | ||
SessionId string | ||
Typ uint8 | ||
SubTyp common.DataTyp | ||
Label string | ||
Description string | ||
} | ||
|
||
func (k KeyInfo) String() string { | ||
v := uint16(k.SubTyp) | ||
s := subTypToString(k.SubTyp) | ||
if s == "" { | ||
v = uint16(k.Typ) | ||
s = typToString(k.Typ) | ||
} | ||
return fmt.Sprintf("Session Id: %s\nTyp: %s (%d)\n", k.SessionId, s, v) | ||
} | ||
|
||
func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) { | ||
o := KeyInfo{} | ||
b := []byte(sessionId) | ||
|
||
if len(k) <= len(b) { | ||
return o, fmt.Errorf("storage key missing") | ||
} | ||
|
||
o.SessionId = sessionId | ||
|
||
o.Typ = uint8(k[0]) | ||
k = k[1:] | ||
o.SessionId = string(k[:len(b)]) | ||
k = k[len(b):] | ||
|
||
if o.Typ == db.DATATYPE_USERDATA { | ||
if len(k) == 0 { | ||
return o, fmt.Errorf("missing subtype key") | ||
} | ||
v := binary.BigEndian.Uint16(k[:2]) | ||
o.SubTyp = common.DataTyp(v) | ||
o.Label = subTypToString(o.SubTyp) | ||
k = k[2:] | ||
} else { | ||
o.Label = typToString(o.Typ) | ||
} | ||
|
||
if len(k) != 0 { | ||
return o, fmt.Errorf("excess key information") | ||
} | ||
|
||
return o, nil | ||
} | ||
|
||
func FromKey(k []byte) (KeyInfo, error) { | ||
o := KeyInfo{} | ||
|
||
if len(k) < 4 { | ||
return o, fmt.Errorf("insufficient key length") | ||
} | ||
|
||
sessionIdBytes := k[1:len(k)-2] | ||
return ToKeyInfo(k, string(sessionIdBytes)) | ||
} | ||
|
||
func subTypToString(v common.DataTyp) string { | ||
return dbTypStr[v + db.DATATYPE_USERDATA + 1] | ||
} | ||
|
||
func typToString(v uint8) string { | ||
return dbTypStr[common.DataTyp(uint16(v))] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// +build debugdb | ||
|
||
package debug | ||
|
||
import ( | ||
"git.defalsify.org/vise.git/db" | ||
|
||
"git.grassecon.net/urdt/ussd/common" | ||
) | ||
|
||
func init() { | ||
DebugCap |= 1 | ||
dbTypStr[db.DATATYPE_STATE] = "internal state" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_ACCOUNT] = "account" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_ACCOUNT_CREATED] = "account created" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_TRACKING_ID] = "tracking id" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_PUBLIC_KEY] = "public key" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_CUSTODIAL_ID] = "custodial id" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_ACCOUNT_PIN] = "account pin" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_ACCOUNT_STATUS] = "account status" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_FIRST_NAME] = "first name" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_FAMILY_NAME] = "family name" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_YOB] = "year of birth" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_LOCATION] = "location" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_GENDER] = "gender" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_OFFERINGS] = "offerings" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_RECIPIENT] = "recipient" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_AMOUNT] = "amount" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_TEMPORARY_VALUE] = "temporary value" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_ACTIVE_SYM] = "active sym" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_ACTIVE_BAL] = "active bal" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_BLOCKED_NUMBER] = "blocked number" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_PUBLIC_KEY_REVERSE] = "public_key_reverse" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_ACTIVE_DECIMAL] = "active decimal" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_ACTIVE_ADDRESS] = "active address" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_VOUCHER_SYMBOLS] = "voucher symbols" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_VOUCHER_BALANCES] = "voucher balances" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_VOUCHER_DECIMALS] = "voucher decimals" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_VOUCHER_ADDRESSES] = "voucher addresses" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_TX_SENDERS] = "tx senders" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_TX_RECIPIENTS] = "tx recipients" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_TX_VALUES] = "tx values" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_TX_ADDRESSES] = "tx addresses" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_TX_HASHES] = "tx hashes" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_TX_DATES] = "tx dates" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_TX_SYMBOLS] = "tx symbols" | ||
dbTypStr[db.DATATYPE_USERDATA + 1 + common.DATA_TX_DECIMALS] = "tx decimals" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package debug | ||
|
||
import ( | ||
"testing" | ||
|
||
"git.grassecon.net/urdt/ussd/common" | ||
"git.defalsify.org/vise.git/db" | ||
) | ||
|
||
func TestDebugDbSubKeyInfo(t *testing.T) { | ||
s := "foo" | ||
b := []byte{0x20} | ||
b = append(b, []byte(s)...) | ||
b = append(b, []byte{0x00, 0x02}...) | ||
r, err := ToKeyInfo(b, s) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if r.SessionId != s { | ||
t.Fatalf("expected %s, got %s", s, r.SessionId) | ||
} | ||
if r.Typ != 32 { | ||
t.Fatalf("expected 64, got %d", r.Typ) | ||
} | ||
if r.SubTyp != 2 { | ||
t.Fatalf("expected 2, got %d", r.SubTyp) | ||
} | ||
if DebugCap & 1 > 0 { | ||
if r.Label != "tracking id" { | ||
t.Fatalf("expected 'tracking id', got '%s'", r.Label) | ||
} | ||
} | ||
} | ||
|
||
func TestDebugDbKeyInfo(t *testing.T) { | ||
s := "bar" | ||
b := []byte{0x10} | ||
b = append(b, []byte(s)...) | ||
r, err := ToKeyInfo(b, s) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if r.SessionId != s { | ||
t.Fatalf("expected %s, got %s", s, r.SessionId) | ||
} | ||
if r.Typ != 16 { | ||
t.Fatalf("expected 16, got %d", r.Typ) | ||
} | ||
if DebugCap & 1 > 0 { | ||
if r.Label != "internal state" { | ||
t.Fatalf("expected 'internal_state', got '%s'", r.Label) | ||
} | ||
} | ||
} | ||
|
||
func TestDebugDbKeyInfoRestore(t *testing.T) { | ||
s := "bar" | ||
b := []byte{db.DATATYPE_USERDATA} | ||
b = append(b, []byte(s)...) | ||
k := common.ToBytes(common.DATA_ACTIVE_SYM) | ||
b = append(b, k...) | ||
|
||
r, err := ToKeyInfo(b, s) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if r.SessionId != s { | ||
t.Fatalf("expected %s, got %s", s, r.SessionId) | ||
} | ||
if r.Typ != 32 { | ||
t.Fatalf("expected 32, got %d", r.Typ) | ||
} | ||
if DebugCap & 1 > 0 { | ||
if r.Label != "active sym" { | ||
t.Fatalf("expected 'active sym', got '%s'", r.Label) | ||
} | ||
} | ||
} |
Oops, something went wrong.