| 1 | package openidscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 6 | "ioscip-go gomod github.com/golang/go/src go1.24.0 io/" |
| 7 | "mathscip-go gomod github.com/golang/go/src go1.24.0 math/" |
| 8 | "regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/" |
| 9 | "strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/" |
| 10 | |
| 11 | "github.com/lestrrat-go/jwx/v3/internal/jsonscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/" |
| 12 | ) |
| 13 | |
| 14 | // https://openid.net/specs/openid-connect-core-1_0.html |
| 15 | // |
| 16 | // End-User's birthday, represented as an ISO 8601:2004 [ISO8601‑2004] YYYY-MM-DD format. |
| 17 | // The year MAY be 0000, indicating that it is omitted. To represent only the year, YYYY |
| 18 | // format is allowed. Note that depending on the underlying platform's date related function, |
| 19 | // providing just year can result in varying month and day, so the implementers need to |
| 20 | // take this factor into account to correctly process the dates. |
| 21 | |
| 22 | type BirthdateClaimscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim# struct { |
| 23 | yearscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#year. *int |
| 24 | monthscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#month. *int |
| 25 | dayscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#day. *int |
| 26 | } |
| 27 | |
| 28 | func (b BirthdateClaimscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#) Yearscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#Year().() int { |
| 29 | if b.yearscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#year. == nil { |
| 30 | return 0 |
| 31 | } |
| 32 | return *(b.yearscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#year.) |
| 33 | } |
| 34 | |
| 35 | func (b BirthdateClaimscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#) Monthscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#Month().() int { |
| 36 | if b.monthscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#month. == nil { |
| 37 | return 0 |
| 38 | } |
| 39 | return *(b.monthscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#month.) |
| 40 | } |
| 41 | |
| 42 | func (b BirthdateClaimscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#) Dayscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#Day().() int { |
| 43 | if b.dayscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#day. == nil { |
| 44 | return 0 |
| 45 | } |
| 46 | return *(b.dayscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#day.) |
| 47 | } |
| 48 | |
| 49 | func (b *BirthdateClaimscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#) UnmarshalJSONscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#UnmarshalJSON().(data []byte) error { |
| 50 | var s string |
| 51 | if err := jsonscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/.Unmarshalscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/json`/Unmarshal().(data, &s); err != nil { |
| 52 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to unmarshal JSON string for birthdate claim: %w`, err) |
| 53 | } |
| 54 | |
| 55 | if err := b.Acceptscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#Accept().(s); err != nil { |
| 56 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to accept JSON value for birthdate claim: %w`, err) |
| 57 | } |
| 58 | return nil |
| 59 | } |
| 60 | |
| 61 | var intSizescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/intSize. int |
| 62 | |
| 63 | func initscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/init().() { |
| 64 | intSizescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/intSize. = 64 |
| 65 | if mathscip-go gomod github.com/golang/go/src go1.24.0 math/.MaxIntscip-go gomod github.com/golang/go/src go1.24.0 math/MaxInt. == mathscip-go gomod github.com/golang/go/src go1.24.0 math/.MaxInt32scip-go gomod github.com/golang/go/src go1.24.0 math/MaxInt32. { |
| 66 | intSizescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/intSize. = 32 |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | func parseBirthdayIntscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/parseBirthdayInt().(s string) int { |
| 71 | i, err := strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.ParseIntscip-go gomod github.com/golang/go/src go1.24.0 strconv/ParseInt().(s, 10, intSizescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/intSize.) |
| 72 | if err != nil { |
| 73 | return 0 |
| 74 | } |
| 75 | return int(i) |
| 76 | } |
| 77 | |
| 78 | var birthdateRxscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/birthdateRx. = regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.24.0 regexp/MustCompile().(`^(\d{4})-(\d{2})-(\d{2})$`) |
| 79 | |
| 80 | // Accept accepts a value read from JSON, and converts it to a BirthdateClaim. |
| 81 | // This method DOES NOT verify the correctness of a date. |
| 82 | // Consumers should check for validity of dates such as Apr 31 et al |
| 83 | func (b *BirthdateClaimscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#) Acceptscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#Accept().(v any) error { |
| 84 | b.yearscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#year. = nil |
| 85 | b.monthscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#month. = nil |
| 86 | b.dayscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#day. = nil |
| 87 | switch v := v.(type) { |
| 88 | case *BirthdateClaimscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#: |
| 89 | if ptr := v.yearscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#year.; ptr != nil { |
| 90 | year := *ptr |
| 91 | b.yearscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#year. = &year |
| 92 | } |
| 93 | if ptr := v.monthscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#month.; ptr != nil { |
| 94 | month := *ptr |
| 95 | b.monthscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#month. = &month |
| 96 | } |
| 97 | if ptr := v.dayscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#day.; ptr != nil { |
| 98 | day := *ptr |
| 99 | b.dayscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#day. = &day |
| 100 | } |
| 101 | return nil |
| 102 | case string: |
| 103 | // yeah, regexp is slow. PR's welcome |
| 104 | indices := birthdateRxscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/birthdateRx..FindStringSubmatchIndexscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringSubmatchIndex().(v) |
| 105 | if indices == nil { |
| 106 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`invalid pattern for birthdate`) |
| 107 | } |
| 108 | var tmp BirthdateClaimscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim# |
| 109 | |
| 110 | // Okay, this really isn't kosher, but we're doing this for |
| 111 | // the coverage game... Because birthdateRx already checked that |
| 112 | // the string contains 3 strings with consecutive decimal values |
| 113 | // we can assume that strconv.ParseInt always succeeds. |
| 114 | // strconv.ParseInt (and strconv.ParseUint that it uses internally) |
| 115 | // only returns range errors, so we should be safe. |
| 116 | year := parseBirthdayIntscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/parseBirthdayInt().(v[indices[2]:indices[3]]) |
| 117 | if year <= 0 { |
| 118 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to parse birthdate year`) |
| 119 | } |
| 120 | tmp.yearscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#year. = &year |
| 121 | |
| 122 | month := parseBirthdayIntscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/parseBirthdayInt().(v[indices[4]:indices[5]]) |
| 123 | if month <= 0 { |
| 124 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to parse birthdate month`) |
| 125 | } |
| 126 | tmp.monthscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#month. = &month |
| 127 | |
| 128 | day := parseBirthdayIntscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/parseBirthdayInt().(v[indices[6]:indices[7]]) |
| 129 | if day <= 0 { |
| 130 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`failed to parse birthdate day`) |
| 131 | } |
| 132 | tmp.dayscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#day. = &day |
| 133 | |
| 134 | *b = tmp |
| 135 | return nil |
| 136 | default: |
| 137 | return fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().(`invalid type for birthdate: %T`, v) |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | func (b BirthdateClaimscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#) encodescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#encode().(dst ioscip-go gomod github.com/golang/go/src go1.24.0 io/.Writerscip-go gomod github.com/golang/go/src go1.24.0 io/Writer#) { |
| 142 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(dst, "%04d-%02d-%02d", b.Yearscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#Year().(), b.Monthscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#Month().(), b.Dayscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#Day().()) |
| 143 | } |
| 144 | |
| 145 | func (b BirthdateClaimscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#) Stringscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#String().() string { |
| 146 | var buf bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer# |
| 147 | b.encodescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#encode().(&buf) |
| 148 | return buf.Stringscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#String().() |
| 149 | } |
| 150 | |
| 151 | func (b BirthdateClaimscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#) MarshalTextscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#MarshalText().() ([]byte, error) { |
| 152 | var buf bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer# |
| 153 | b.encodescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/jwt/openid`/BirthdateClaim#encode().(&buf) |
| 154 | return buf.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().(), nil |
| 155 | } |