-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathconditional_access_transfer_methods.go
54 lines (52 loc) · 1.77 KB
/
conditional_access_transfer_methods.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package models
import (
"math"
"strings"
)
type ConditionalAccessTransferMethods int
const (
NONE_CONDITIONALACCESSTRANSFERMETHODS = 1
DEVICECODEFLOW_CONDITIONALACCESSTRANSFERMETHODS = 2
AUTHENTICATIONTRANSFER_CONDITIONALACCESSTRANSFERMETHODS = 4
UNKNOWNFUTUREVALUE_CONDITIONALACCESSTRANSFERMETHODS = 8
)
func (i ConditionalAccessTransferMethods) String() string {
var values []string
options := []string{"none", "deviceCodeFlow", "authenticationTransfer", "unknownFutureValue"}
for p := 0; p < 4; p++ {
mantis := ConditionalAccessTransferMethods(int(math.Pow(2, float64(p))))
if i&mantis == mantis {
values = append(values, options[p])
}
}
return strings.Join(values, ",")
}
func ParseConditionalAccessTransferMethods(v string) (any, error) {
var result ConditionalAccessTransferMethods
values := strings.Split(v, ",")
for _, str := range values {
switch str {
case "none":
result |= NONE_CONDITIONALACCESSTRANSFERMETHODS
case "deviceCodeFlow":
result |= DEVICECODEFLOW_CONDITIONALACCESSTRANSFERMETHODS
case "authenticationTransfer":
result |= AUTHENTICATIONTRANSFER_CONDITIONALACCESSTRANSFERMETHODS
case "unknownFutureValue":
result |= UNKNOWNFUTUREVALUE_CONDITIONALACCESSTRANSFERMETHODS
default:
return nil, nil
}
}
return &result, nil
}
func SerializeConditionalAccessTransferMethods(values []ConditionalAccessTransferMethods) []string {
result := make([]string, len(values))
for i, v := range values {
result[i] = v.String()
}
return result
}
func (i ConditionalAccessTransferMethods) isMultiValue() bool {
return true
}