mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
add protocol field encoder
This commit is contained in:
parent
b2605b7961
commit
fb57ad79f5
1 changed files with 29 additions and 0 deletions
|
@ -5,6 +5,7 @@ package messages
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/bridgefingerprint"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/bridgefingerprint"
|
||||||
|
@ -149,3 +150,31 @@ func DecodeClientPollResponse(data []byte) (*ClientPollResponse, error) {
|
||||||
|
|
||||||
return &message, nil
|
return &message, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ClientConnectionMetadata struct {
|
||||||
|
ClientID string `json:"client_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (meta *ClientConnectionMetadata) EncodeConnectionMetadata() (string, error) {
|
||||||
|
jsonData, err := json.Marshal(meta)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return base64.RawURLEncoding.EncodeToString(jsonData), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DecodeConnectionMetadata(data string) (*ClientConnectionMetadata, error) {
|
||||||
|
decodedData, err := base64.RawURLEncoding.DecodeString(data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var meta ClientConnectionMetadata
|
||||||
|
err = json.Unmarshal(decodedData, &meta)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &meta, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue