blob: 2b375dab27bd585fd9e5b6ba8fe3907fa54cc985 [file] [log] [blame]
Scott Baker8461e152019-10-01 14:44:30 -07001package mstypes
2
3import (
4 "bytes"
5 "errors"
6
7 "gopkg.in/jcmturner/rpc.v1/ndr"
8)
9
10// Compression format assigned numbers.
11const (
12 CompressionFormatNone uint16 = 0
13 CompressionFormatLZNT1 uint16 = 2
14 CompressionFormatXPress uint16 = 3
15 CompressionFormatXPressHuff uint16 = 4
16)
17
18// ClaimsSourceTypeAD https://msdn.microsoft.com/en-us/library/hh553809.aspx
19const ClaimsSourceTypeAD uint16 = 1
20
21// Claim Type assigned numbers
22const (
23 ClaimTypeIDInt64 uint16 = 1
24 ClaimTypeIDUInt64 uint16 = 2
25 ClaimTypeIDString uint16 = 3
26 ClaimsTypeIDBoolean uint16 = 6
27)
28
29// ClaimsBlob implements https://msdn.microsoft.com/en-us/library/hh554119.aspx
30type ClaimsBlob struct {
31 Size uint32
32 EncodedBlob EncodedBlob
33}
34
35// EncodedBlob are the bytes of the encoded Claims
36type EncodedBlob []byte
37
38// Size returns the size of the bytes of the encoded Claims
39func (b EncodedBlob) Size(c interface{}) int {
40 cb := c.(ClaimsBlob)
41 return int(cb.Size)
42}
43
44// ClaimsSetMetadata implements https://msdn.microsoft.com/en-us/library/hh554073.aspx
45type ClaimsSetMetadata struct {
46 ClaimsSetSize uint32
47 ClaimsSetBytes []byte `ndr:"pointer,conformant"`
48 CompressionFormat uint16 // Enum see constants for options
49 UncompressedClaimsSetSize uint32
50 ReservedType uint16
51 ReservedFieldSize uint32
52 ReservedField []byte `ndr:"pointer,conformant"`
53}
54
55// ClaimsSet reads the ClaimsSet type from the NDR encoded ClaimsSetBytes in the ClaimsSetMetadata
56func (m *ClaimsSetMetadata) ClaimsSet() (c ClaimsSet, err error) {
57 if len(m.ClaimsSetBytes) < 1 {
58 err = errors.New("no bytes available for ClaimsSet")
59 return
60 }
61 // TODO switch statement to decompress ClaimsSetBytes
62 if m.CompressionFormat != CompressionFormatNone {
63 err = errors.New("compressed ClaimsSet not currently supported")
64 return
65 }
66 dec := ndr.NewDecoder(bytes.NewReader(m.ClaimsSetBytes))
67 err = dec.Decode(&c)
68 return
69}
70
71// ClaimsSet implements https://msdn.microsoft.com/en-us/library/hh554122.aspx
72type ClaimsSet struct {
73 ClaimsArrayCount uint32
74 ClaimsArrays []ClaimsArray `ndr:"pointer,conformant"`
75 ReservedType uint16
76 ReservedFieldSize uint32
77 ReservedField []byte `ndr:"pointer,conformant"`
78}
79
80// ClaimsArray implements https://msdn.microsoft.com/en-us/library/hh536458.aspx
81type ClaimsArray struct {
82 ClaimsSourceType uint16
83 ClaimsCount uint32
84 ClaimEntries []ClaimEntry `ndr:"pointer,conformant"`
85}
86
87// ClaimEntry is a NDR union that implements https://msdn.microsoft.com/en-us/library/hh536374.aspx
88type ClaimEntry struct {
89 ID string `ndr:"pointer,conformant,varying"`
90 Type uint16 `ndr:"unionTag"`
91 TypeInt64 ClaimTypeInt64 `ndr:"unionField"`
92 TypeUInt64 ClaimTypeUInt64 `ndr:"unionField"`
93 TypeString ClaimTypeString `ndr:"unionField"`
94 TypeBool ClaimTypeBoolean `ndr:"unionField"`
95}
96
97// SwitchFunc is the ClaimEntry union field selection function
98func (u ClaimEntry) SwitchFunc(_ interface{}) string {
99 switch u.Type {
100 case ClaimTypeIDInt64:
101 return "TypeInt64"
102 case ClaimTypeIDUInt64:
103 return "TypeUInt64"
104 case ClaimTypeIDString:
105 return "TypeString"
106 case ClaimsTypeIDBoolean:
107 return "TypeBool"
108 }
109 return ""
110}
111
112// ClaimTypeInt64 is a claim of type int64
113type ClaimTypeInt64 struct {
114 ValueCount uint32
115 Value []int64 `ndr:"pointer,conformant"`
116}
117
118// ClaimTypeUInt64 is a claim of type uint64
119type ClaimTypeUInt64 struct {
120 ValueCount uint32
121 Value []uint64 `ndr:"pointer,conformant"`
122}
123
124// ClaimTypeString is a claim of type string
125type ClaimTypeString struct {
126 ValueCount uint32
127 Value []LPWSTR `ndr:"pointer,conformant"`
128}
129
130// ClaimTypeBoolean is a claim of type bool
131type ClaimTypeBoolean struct {
132 ValueCount uint32
133 Value []bool `ndr:"pointer,conformant"`
134}