Skip to content

Commit 32d8577

Browse files
committed
backend/pip: make pipmsg exportable via gomobile
1 parent f879a10 commit 32d8577

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

intra/backend/ipn_pipkeygen.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,25 @@ type PipKeyProvider interface {
6464
Finalize(blingSig string) (*PipKey, error)
6565
}
6666

67+
// Strx exists for gomobile type export support for PipMsg & PipToken
68+
type Strx struct {
69+
s string
70+
}
71+
6772
// PipToken is a 32 byte random token for bespoke auth.
68-
type PipToken string
73+
type PipToken Strx
6974

7075
// PipMsg is a 64 byte hex encoded string that contains:
7176
// - first 32 bytes as message (random)
7277
// - next 32 bytes as client identifier (random)
73-
type PipMsg string
78+
type PipMsg Strx
7479

7580
// AsPipMsg typecast m to PipMsg.
7681
// m must be a 64 bytes hex string
7782
// (32b for msg + 32b for opaque-id).
7883
// Returns nil if the string m is nil or not a valid PipMsg.
7984
func AsPipMsg(m string) *PipMsg {
80-
p := (PipMsg)(m)
85+
p := (PipMsg)(Strx{s: m})
8186
if !p.ok() {
8287
return nil
8388
}
@@ -93,7 +98,7 @@ func NewPipMsgWith(tok *PipToken) *PipMsg {
9398
log.E("pipkey: new: invalid msg size; want %d, got %d", 2*msgsize, len(msg))
9499
return nil
95100
}
96-
return pipmsgof(msg + (string)(*tok))
101+
return pipmsgof(msg + tok.s)
97102
}
98103

99104
// go.dev/play/p/hPFgE9s9tMP
@@ -112,38 +117,38 @@ func (p *PipMsg) v() string {
112117
if p == nil {
113118
return ""
114119
}
115-
return string(*p)
120+
return p.s
116121
}
117122

118123
func (p *PipMsg) ok() bool {
119-
return p != nil && len(*p) >= 2*(msgsize+cidsize)
124+
return p != nil && len(p.s) >= 2*(msgsize+cidsize)
120125
}
121126

122127
func (p *PipMsg) msg() []byte {
123128
if p == nil || !p.ok() {
124-
log.E("pipkey: msg: invalid; got %d", len(*p))
129+
log.E("pipkey: msg: invalid; got %d", len(p.s))
125130
return nil
126131
}
127132
// first 32 bytes are the message
128-
return hex2byte(string(*p)[:2*msgsize])
133+
return hex2byte(p.s[:2*msgsize])
129134
}
130135

131136
func (p *PipMsg) cid() []byte {
132137
if p == nil || !p.ok() {
133-
log.E("pipkey: cid: invalid; got %d", len(*p))
138+
log.E("pipkey: cid: invalid; got %d", len(p.s))
134139
return nil
135140
}
136141
// next 32 bytes are the client identifier
137-
return hex2byte(string(*p)[2*msgsize : 2*(msgsize+cidsize)])
142+
return hex2byte(p.s[2*msgsize : 2*(msgsize+cidsize)])
138143
}
139144

140145
// Opaque returns the client id part of the PipMsg as hex string.
141146
func (p *PipMsg) Opaque() *PipToken {
142147
if p == nil || !p.ok() {
143-
log.E("pipkey: opaque: invalid; got %d", len(*p))
148+
log.E("pipkey: opaque: invalid; got %d", len(p.s))
144149
return nil
145150
}
146-
tok, err := asPipToken(string(*p)[2*(msgsize) : 2*(msgsize+cidsize)])
151+
tok, err := asPipToken(p.s[2*(msgsize) : 2*(msgsize+cidsize)])
147152
if err != nil {
148153
log.E("pipkey: opaque conv: %v", err)
149154
return nil
@@ -556,7 +561,7 @@ func asPipToken(tok string) (*PipToken, error) {
556561
return nil, errTokenCreat
557562
}
558563
// StrOf interns the string
559-
return (*PipToken)(&tok), nil
564+
return (*PipToken)(&Strx{s: tok}), nil
560565
}
561566

562567
func token() string {

intra/log/logger.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ func (l LogLevel) s() string {
187187
}
188188
}
189189

190-
const consoleStacktraceSep = "\n<===>\n"
191-
192190
const defaultLevel = INFO
193191
const defaultClevel = STACKTRACE
194192

0 commit comments

Comments
 (0)