Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 1 | package mstypes |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "errors" |
| 6 | |
| 7 | "gopkg.in/jcmturner/rpc.v1/ndr" |
| 8 | ) |
| 9 | |
| 10 | // Compression format assigned numbers. |
| 11 | const ( |
| 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 |
| 19 | const ClaimsSourceTypeAD uint16 = 1 |
| 20 | |
| 21 | // Claim Type assigned numbers |
| 22 | const ( |
| 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 |
| 30 | type ClaimsBlob struct { |
| 31 | Size uint32 |
| 32 | EncodedBlob EncodedBlob |
| 33 | } |
| 34 | |
| 35 | // EncodedBlob are the bytes of the encoded Claims |
| 36 | type EncodedBlob []byte |
| 37 | |
| 38 | // Size returns the size of the bytes of the encoded Claims |
| 39 | func (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 |
| 45 | type 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 |
| 56 | func (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 |
| 72 | type 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 |
| 81 | type 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 |
| 88 | type 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 |
| 98 | func (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 |
| 113 | type ClaimTypeInt64 struct { |
| 114 | ValueCount uint32 |
| 115 | Value []int64 `ndr:"pointer,conformant"` |
| 116 | } |
| 117 | |
| 118 | // ClaimTypeUInt64 is a claim of type uint64 |
| 119 | type ClaimTypeUInt64 struct { |
| 120 | ValueCount uint32 |
| 121 | Value []uint64 `ndr:"pointer,conformant"` |
| 122 | } |
| 123 | |
| 124 | // ClaimTypeString is a claim of type string |
| 125 | type ClaimTypeString struct { |
| 126 | ValueCount uint32 |
| 127 | Value []LPWSTR `ndr:"pointer,conformant"` |
| 128 | } |
| 129 | |
| 130 | // ClaimTypeBoolean is a claim of type bool |
| 131 | type ClaimTypeBoolean struct { |
| 132 | ValueCount uint32 |
| 133 | Value []bool `ndr:"pointer,conformant"` |
| 134 | } |