github.com/psiphon-labs/psiphon-tunnel-core@v2.0.28+incompatible/psiphon/upstreamproxy/go-ntlm/ntlm/version.go (about) 1 //Copyright 2013 Thomson Reuters Global Resources. BSD License please see License file for more information 2 3 package ntlm 4 5 import ( 6 "bytes" 7 "encoding/binary" 8 "errors" 9 "fmt" 10 ) 11 12 type VersionStruct struct { 13 ProductMajorVersion uint8 14 ProductMinorVersion uint8 15 ProductBuild uint16 16 Reserved []byte 17 NTLMRevisionCurrent uint8 18 } 19 20 func ReadVersionStruct(structSource []byte) (*VersionStruct, error) { 21 versionStruct := new(VersionStruct) 22 23 // [Psiphon] 24 // Don't panic on malformed remote input. 25 if len(structSource) < 8 { 26 return nil, errors.New("invalid version struct") 27 } 28 29 versionStruct.ProductMajorVersion = uint8(structSource[0]) 30 versionStruct.ProductMinorVersion = uint8(structSource[1]) 31 versionStruct.ProductBuild = binary.LittleEndian.Uint16(structSource[2:4]) 32 versionStruct.Reserved = structSource[4:7] 33 versionStruct.NTLMRevisionCurrent = uint8(structSource[7]) 34 35 return versionStruct, nil 36 } 37 38 func (v *VersionStruct) String() string { 39 return fmt.Sprintf("%d.%d.%d Ntlm %d", v.ProductMajorVersion, v.ProductMinorVersion, v.ProductBuild, v.NTLMRevisionCurrent) 40 } 41 42 func (v *VersionStruct) Bytes() []byte { 43 dest := make([]byte, 0, 8) 44 buffer := bytes.NewBuffer(dest) 45 46 binary.Write(buffer, binary.LittleEndian, v.ProductMajorVersion) 47 binary.Write(buffer, binary.LittleEndian, v.ProductMinorVersion) 48 binary.Write(buffer, binary.LittleEndian, v.ProductBuild) 49 buffer.Write(make([]byte, 3)) 50 binary.Write(buffer, binary.LittleEndian, uint8(v.NTLMRevisionCurrent)) 51 52 return buffer.Bytes() 53 }