| 1 | package josescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/ |
| 2 | |
| 3 | import ( |
| 4 | "bufioscip-go gomod github.com/golang/go/src go1.24.0 bufio/" |
| 5 | "bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/" |
| 6 | "contextscip-go gomod github.com/golang/go/src go1.24.0 context/" |
| 7 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 8 | "ioscip-go gomod github.com/golang/go/src go1.24.0 io/" |
| 9 | "os/execscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/" |
| 10 | "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/" |
| 11 | "syncscip-go gomod github.com/golang/go/src go1.24.0 sync/" |
| 12 | "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/" |
| 13 | |
| 14 | "github.com/lestrrat-go/jwx/v3/internal/jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/" |
| 15 | ) |
| 16 | |
| 17 | var executablePathscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/executablePath. string |
| 18 | var muExecutablePathscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/muExecutablePath. syncscip-go gomod github.com/golang/go/src go1.24.0 sync/.RWMutexscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex# |
| 19 | |
| 20 | func initscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/init().() { |
| 21 | findExecutablescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/findExecutable().() |
| 22 | } |
| 23 | |
| 24 | func SetExecutablescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/SetExecutable().(path string) { |
| 25 | muExecutablePathscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/muExecutablePath..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#Lock().() |
| 26 | defer muExecutablePathscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/muExecutablePath..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#Unlock().() |
| 27 | executablePathscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/executablePath. = path |
| 28 | } |
| 29 | |
| 30 | func findExecutablescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/findExecutable().() { |
| 31 | p, err := execscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/.LookPathscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/LookPath().("jose") |
| 32 | if err == nil { |
| 33 | SetExecutablescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/SetExecutable().(p) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | func ExecutablePathscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/ExecutablePath().() string { |
| 38 | muExecutablePathscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/muExecutablePath..RLockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RLock().() |
| 39 | defer muExecutablePathscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/muExecutablePath..RUnlockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RUnlock().() |
| 40 | |
| 41 | return executablePathscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/executablePath. |
| 42 | } |
| 43 | |
| 44 | func Availablescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/Available().() bool { |
| 45 | muExecutablePathscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/muExecutablePath..RLockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RLock().() |
| 46 | defer muExecutablePathscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/muExecutablePath..RUnlockscip-go gomod github.com/golang/go/src go1.24.0 sync/RWMutex#RUnlock().() |
| 47 | |
| 48 | return executablePathscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/executablePath. != "" |
| 49 | } |
| 50 | |
| 51 | func RunJoseCommandscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/RunJoseCommand().(ctx contextscip-go gomod github.com/golang/go/src go1.24.0 context/.Contextscip-go gomod github.com/golang/go/src go1.24.0 context/Context#, t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#, args []string, outw, errw 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#) error { |
| 52 | var errout 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# |
| 53 | var capout 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# |
| 54 | |
| 55 | cmd := execscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/.CommandContextscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/CommandContext().(ctx, ExecutablePathscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/ExecutablePath().(), args...) |
| 56 | if outw == nil { |
| 57 | cmd.Stdoutscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/Cmd#Stdout. = &capout |
| 58 | } else { |
| 59 | cmd.Stdoutscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/Cmd#Stdout. = ioscip-go gomod github.com/golang/go/src go1.24.0 io/.MultiWriterscip-go gomod github.com/golang/go/src go1.24.0 io/MultiWriter().(outw, &capout) |
| 60 | } |
| 61 | |
| 62 | if errw == nil { |
| 63 | cmd.Stderrscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/Cmd#Stderr. = &errout |
| 64 | } else { |
| 65 | cmd.Stderrscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/Cmd#Stderr. = ioscip-go gomod github.com/golang/go/src go1.24.0 io/.MultiWriterscip-go gomod github.com/golang/go/src go1.24.0 io/MultiWriter().(outw, &errout) |
| 66 | } |
| 67 | |
| 68 | t.Logfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Logf().("Executing `%s %s`\n", ExecutablePathscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/ExecutablePath().(), stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.24.0 strings/Join().(args, " ")) |
| 69 | if err := cmd.Runscip-go gomod github.com/golang/go/src go1.24.0 `os/exec`/Cmd#Run().(); err != nil { |
| 70 | t.Logfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Logf().(`failed to execute command: %s`, err) |
| 71 | |
| 72 | if capout.Lenscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Len().() > 0 { |
| 73 | t.Logfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Logf().("captured output: %s", capout.Stringscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#String().()) |
| 74 | } |
| 75 | |
| 76 | if errout.Lenscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Len().() > 0 { |
| 77 | t.Logfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Logf().("captured error: %s", errout.Stringscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#String().()) |
| 78 | } |
| 79 | |
| 80 | 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 execute command: %w`, err) |
| 81 | } |
| 82 | |
| 83 | return nil |
| 84 | } |
| 85 | |
| 86 | type AlgorithmSetscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/AlgorithmSet# struct { |
| 87 | datascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/AlgorithmSet#data. map[string]struct{} |
| 88 | } |
| 89 | |
| 90 | func NewAlgorithmSetscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/NewAlgorithmSet().() *AlgorithmSetscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/AlgorithmSet# { |
| 91 | return &AlgorithmSetscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/AlgorithmSet#{ |
| 92 | datascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/AlgorithmSet#data.: make(map[string]struct{}), |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | func (set *AlgorithmSetscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/AlgorithmSet#) Addscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/AlgorithmSet#Add().(s string) { |
| 97 | set.datascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/AlgorithmSet#data.[s] = struct{}{} |
| 98 | } |
| 99 | |
| 100 | func (set *AlgorithmSetscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/AlgorithmSet#) Hasscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/AlgorithmSet#Has().(s string) bool { |
| 101 | _, ok := set.datascip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/AlgorithmSet#data.[s] |
| 102 | return ok |
| 103 | } |
| 104 | |
| 105 | func Algorithmsscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/Algorithms().(ctx contextscip-go gomod github.com/golang/go/src go1.24.0 context/.Contextscip-go gomod github.com/golang/go/src go1.24.0 context/Context#, t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) (*AlgorithmSetscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/AlgorithmSet#, error) { |
| 106 | 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# |
| 107 | if err := RunJoseCommandscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/RunJoseCommand().(ctx, t, []string{"alg"}, &buf, nil); err != nil { |
| 108 | return nil, 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 generate jose tool's supported algorithms: %w`, err) |
| 109 | } |
| 110 | |
| 111 | set := NewAlgorithmSetscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/NewAlgorithmSet().() |
| 112 | |
| 113 | scanner := bufioscip-go gomod github.com/golang/go/src go1.24.0 bufio/.NewScannerscip-go gomod github.com/golang/go/src go1.24.0 bufio/NewScanner().(&buf) |
| 114 | for scanner.Scanscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Scan().() { |
| 115 | alg := scanner.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().() |
| 116 | set.Addscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/AlgorithmSet#Add().(alg) |
| 117 | } |
| 118 | return set, nil |
| 119 | } |
| 120 | |
| 121 | // GenerateJwk creates a new key using the jose tool, and returns its filename and |
| 122 | // a cleanup function. |
| 123 | // The caller is responsible for calling the cleanup |
| 124 | // function and make sure all resources are released |
| 125 | func GenerateJwkscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/GenerateJwk().(ctx contextscip-go gomod github.com/golang/go/src go1.24.0 context/.Contextscip-go gomod github.com/golang/go/src go1.24.0 context/Context#, t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#, template string) (string, func(), error) { |
| 126 | t.Helperscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Helper().() |
| 127 | |
| 128 | file, cleanup, err := jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/.CreateTempFilescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/CreateTempFile().(t.TempDirscip-go gomod github.com/golang/go/src go1.24.0 testing/common#TempDir().(), "jwx-jose-key-*.jwk") |
| 129 | if err != nil { |
| 130 | return "", nil, 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 create temporary file: %w`, err) |
| 131 | } |
| 132 | |
| 133 | if err := RunJoseCommandscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/RunJoseCommand().(ctx, t, []string{"jwk", "gen", "-i", template, "-o", file.Namescip-go gomod github.com/golang/go/src go1.24.0 os/File#Name().()}, nil, nil); err != nil { |
| 134 | return "", nil, 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 generate key: %w`, err) |
| 135 | } |
| 136 | |
| 137 | return file.Namescip-go gomod github.com/golang/go/src go1.24.0 os/File#Name().(), cleanup, nil |
| 138 | } |
| 139 | |
| 140 | // EncryptJwe creates an encrypted JWE message and returns its filename and |
| 141 | // a cleanup function. |
| 142 | // The caller is responsible for calling the cleanup |
| 143 | // function and make sure all resources are released |
| 144 | func EncryptJwescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/EncryptJwe().(ctx contextscip-go gomod github.com/golang/go/src go1.24.0 context/.Contextscip-go gomod github.com/golang/go/src go1.24.0 context/Context#, t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#, payload []byte, alg string, keyfile string, enc string, compact bool) (string, func(), error) { |
| 145 | t.Helperscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Helper().() |
| 146 | |
| 147 | var arg string |
| 148 | if alg == "dir" { |
| 149 | arg = fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().(`{"protected":{"alg":"dir","enc":"%s"}}`, enc) |
| 150 | } else { |
| 151 | arg = fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Sprintf().(`{"protected":{"enc":"%s"}}`, enc) |
| 152 | } |
| 153 | |
| 154 | cmdargs := []string{"jwe", "enc", "-k", keyfile, "-i", arg} |
| 155 | if compact { |
| 156 | cmdargs = append(cmdargs, "-c") |
| 157 | } |
| 158 | |
| 159 | var pfile string |
| 160 | if len(payload) > 0 { |
| 161 | fn, pcleanup, perr := jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/.WriteFilescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/WriteFile().(t.TempDirscip-go gomod github.com/golang/go/src go1.24.0 testing/common#TempDir().(), "jwx-jose-payload-*", bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.24.0 bytes/NewReader().(payload)) |
| 162 | if perr != nil { |
| 163 | return "", nil, 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 write payload to file: %w`, perr) |
| 164 | } |
| 165 | |
| 166 | cmdargs = append(cmdargs, "-I", fn) |
| 167 | pfile = fn |
| 168 | defer pcleanup() |
| 169 | } |
| 170 | |
| 171 | ofile, ocleanup, oerr := jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/.CreateTempFilescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/CreateTempFile().(t.TempDirscip-go gomod github.com/golang/go/src go1.24.0 testing/common#TempDir().(), `jwx-jose-key-*.jwe`) |
| 172 | if oerr != nil { |
| 173 | return "", nil, 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 create temporary file: %w`, oerr) |
| 174 | } |
| 175 | |
| 176 | cmdargs = append(cmdargs, "-o", ofile.Namescip-go gomod github.com/golang/go/src go1.24.0 os/File#Name().()) |
| 177 | |
| 178 | if err := RunJoseCommandscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/RunJoseCommand().(ctx, t, cmdargs, nil, nil); err != nil { |
| 179 | defer ocleanup() |
| 180 | if pfile != "" { |
| 181 | jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/.DumpFilescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/DumpFile().(t, pfile) |
| 182 | } |
| 183 | jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/.DumpFilescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/DumpFile().(t, keyfile) |
| 184 | return "", nil, 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 encrypt message: %w`, err) |
| 185 | } |
| 186 | |
| 187 | return ofile.Namescip-go gomod github.com/golang/go/src go1.24.0 os/File#Name().(), ocleanup, nil |
| 188 | } |
| 189 | |
| 190 | func DecryptJwescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/DecryptJwe().(ctx contextscip-go gomod github.com/golang/go/src go1.24.0 context/.Contextscip-go gomod github.com/golang/go/src go1.24.0 context/Context#, t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#, cfile, kfile string) ([]byte, error) { |
| 191 | t.Helperscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Helper().() |
| 192 | |
| 193 | cmdargs := []string{"jwe", "dec", "-i", cfile, "-k", kfile} |
| 194 | var output 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# |
| 195 | if err := RunJoseCommandscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/RunJoseCommand().(ctx, t, cmdargs, &output, nil); err != nil { |
| 196 | jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/.DumpFilescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/DumpFile().(t, cfile) |
| 197 | jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/.DumpFilescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/DumpFile().(t, kfile) |
| 198 | |
| 199 | return nil, 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 decrypt message: %w`, err) |
| 200 | } |
| 201 | |
| 202 | return output.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().(), nil |
| 203 | } |
| 204 | |
| 205 | func FmtJwescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/FmtJwe().(ctx contextscip-go gomod github.com/golang/go/src go1.24.0 context/.Contextscip-go gomod github.com/golang/go/src go1.24.0 context/Context#, t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#, data []byte) ([]byte, error) { |
| 206 | t.Helperscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Helper().() |
| 207 | |
| 208 | fn, pcleanup, perr := jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/.WriteFilescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/WriteFile().(t.TempDirscip-go gomod github.com/golang/go/src go1.24.0 testing/common#TempDir().(), "jwx-jose-fmt-data-*", bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.24.0 bytes/NewReader().(data)) |
| 209 | if perr != nil { |
| 210 | return nil, 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 write data to file: %w`, perr) |
| 211 | } |
| 212 | defer pcleanup() |
| 213 | |
| 214 | cmdargs := []string{"jwe", "fmt", "-i", fn} |
| 215 | |
| 216 | var output 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# |
| 217 | if err := RunJoseCommandscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/RunJoseCommand().(ctx, t, cmdargs, &output, nil); err != nil { |
| 218 | jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/.DumpFilescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/DumpFile().(t, fn) |
| 219 | |
| 220 | return nil, 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 format JWE message: %w`, err) |
| 221 | } |
| 222 | |
| 223 | return output.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().(), nil |
| 224 | } |
| 225 | |
| 226 | // SignJws signs a message and returns its filename and |
| 227 | // a cleanup function. |
| 228 | // The caller is responsible for calling the cleanup |
| 229 | // function and make sure all resources are released |
| 230 | func SignJwsscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/SignJws().(ctx contextscip-go gomod github.com/golang/go/src go1.24.0 context/.Contextscip-go gomod github.com/golang/go/src go1.24.0 context/Context#, t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#, payload []byte, keyfile string, compact bool) (string, func(), error) { |
| 231 | t.Helperscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Helper().() |
| 232 | |
| 233 | cmdargs := []string{"jws", "sig", "-k", keyfile} |
| 234 | if compact { |
| 235 | cmdargs = append(cmdargs, "-c") |
| 236 | } |
| 237 | |
| 238 | var pfile string |
| 239 | if len(payload) > 0 { |
| 240 | fn, pcleanup, perr := jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/.WriteFilescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/WriteFile().(t.TempDirscip-go gomod github.com/golang/go/src go1.24.0 testing/common#TempDir().(), "jwx-jose-payload-*", bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.24.0 bytes/NewReader().(payload)) |
| 241 | if perr != nil { |
| 242 | return "", nil, 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 write payload to file: %w`, perr) |
| 243 | } |
| 244 | |
| 245 | cmdargs = append(cmdargs, "-I", fn) |
| 246 | pfile = fn |
| 247 | defer pcleanup() |
| 248 | } |
| 249 | |
| 250 | ofile, ocleanup, oerr := jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/.CreateTempFilescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/CreateTempFile().(t.TempDirscip-go gomod github.com/golang/go/src go1.24.0 testing/common#TempDir().(), `jwx-jose-sig-*.jws`) |
| 251 | if oerr != nil { |
| 252 | return "", nil, 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 create temporary file: %w`, oerr) |
| 253 | } |
| 254 | |
| 255 | cmdargs = append(cmdargs, "-o", ofile.Namescip-go gomod github.com/golang/go/src go1.24.0 os/File#Name().()) |
| 256 | |
| 257 | if err := RunJoseCommandscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/RunJoseCommand().(ctx, t, cmdargs, nil, nil); err != nil { |
| 258 | defer ocleanup() |
| 259 | if pfile != "" { |
| 260 | jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/.DumpFilescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/DumpFile().(t, pfile) |
| 261 | } |
| 262 | jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/.DumpFilescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/DumpFile().(t, keyfile) |
| 263 | return "", nil, 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 sign message: %w`, err) |
| 264 | } |
| 265 | |
| 266 | return ofile.Namescip-go gomod github.com/golang/go/src go1.24.0 os/File#Name().(), ocleanup, nil |
| 267 | } |
| 268 | |
| 269 | func VerifyJwsscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/VerifyJws().(ctx contextscip-go gomod github.com/golang/go/src go1.24.0 context/.Contextscip-go gomod github.com/golang/go/src go1.24.0 context/Context#, t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#, cfile, kfile string) ([]byte, error) { |
| 270 | t.Helperscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Helper().() |
| 271 | |
| 272 | cmdargs := []string{"jws", "ver", "-i", cfile, "-k", kfile, "-O-"} |
| 273 | var output 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# |
| 274 | if err := RunJoseCommandscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jose`/RunJoseCommand().(ctx, t, cmdargs, &output, nil); err != nil { |
| 275 | jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/.DumpFilescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/DumpFile().(t, cfile) |
| 276 | jwxtestscip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/.DumpFilescip-go gomod github.com/lestrrat-go/jwx/v3 . `github.com/lestrrat-go/jwx/v3/internal/jwxtest`/DumpFile().(t, kfile) |
| 277 | |
| 278 | return nil, 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 decrypt message: %w`, err) |
| 279 | } |
| 280 | |
| 281 | return output.Bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/Buffer#Bytes().(), nil |
| 282 | } |