package mtproxy
import (
"github.com/go-faster/errors"
"github.com/gotd/td/internal/proto/codec"
)
type SecretType int
const (
Simple SecretType = iota + 1
Secured
TLS
)
type Secret struct {
Secret []byte
Tag byte
CloakHost string
Type SecretType
}
func (s Secret ) ExpectedCodec () (cdc codec .Codec , _ bool ) {
switch s .Tag {
case codec .AbridgedClientStart [0 ]:
cdc = codec .Abridged {}
case codec .IntermediateClientStart [0 ]:
cdc = codec .Intermediate {}
case codec .PaddedIntermediateClientStart [0 ]:
cdc = codec .PaddedIntermediate {}
default :
return nil , false
}
return cdc , true
}
func ParseSecret (secret []byte ) (Secret , error ) {
r := Secret {
Secret : secret ,
}
const simpleLength = 16
switch {
case len (secret ) == 1 +simpleLength :
r .Type = Secured
r .Tag = secret [0 ]
secret = secret [1 :]
r .Secret = secret [:simpleLength ]
case len (secret ) > simpleLength :
r .Type = TLS
r .Tag = secret [0 ]
secret = secret [1 :]
r .Secret = secret [:simpleLength ]
r .CloakHost = string (secret [simpleLength :])
case len (secret ) == simpleLength :
r .Type = Simple
default :
return Secret {}, errors .Errorf ("invalid secret %q" , string (secret ))
}
if r .Type != Simple {
switch r .Tag {
case codec .AbridgedClientStart [0 ],
codec .IntermediateClientStart [0 ],
codec .PaddedIntermediateClientStart [0 ]:
default :
return Secret {}, errors .Errorf ("unknown tag %+x" , r .Tag )
}
}
return r , nil
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .