@@ -138,8 +138,8 @@ func GenerateX25519Jwk() (jwk.Key, error) {
138138 return k , nil
139139}
140140
141- func WriteFile (template string , src io.Reader ) (string , func (), error ) {
142- file , cleanup , err := CreateTempFile (template )
141+ func WriteFile (dir , template string , src io.Reader ) (string , func (), error ) {
142+ file , cleanup , err := CreateTempFile (dir , template )
143143 if err != nil {
144144 return "" , nil , fmt .Errorf (`failed to create temporary file: %w` , err )
145145 }
@@ -156,14 +156,14 @@ func WriteFile(template string, src io.Reader) (string, func(), error) {
156156 return file .Name (), cleanup , nil
157157}
158158
159- func WriteJSONFile (template string , v interface {}) (string , func (), error ) {
159+ func WriteJSONFile (dir , template string , v interface {}) (string , func (), error ) {
160160 var buf bytes.Buffer
161161
162162 enc := json .NewEncoder (& buf )
163163 if err := enc .Encode (v ); err != nil {
164164 return "" , nil , fmt .Errorf (`failed to encode object to JSON: %w` , err )
165165 }
166- return WriteFile (template , & buf )
166+ return WriteFile (dir , template , & buf )
167167}
168168
169169func DumpFile (t * testing.T , file string ) {
@@ -215,8 +215,8 @@ func DumpFile(t *testing.T, file string) {
215215 t .Logf ("=== END %s (formatted JSON) ===" , file )
216216}
217217
218- func CreateTempFile (template string ) (* os.File , func (), error ) {
219- file , err := os .CreateTemp ("" , template )
218+ func CreateTempFile (dir , template string ) (* os.File , func (), error ) {
219+ file , err := os .CreateTemp (dir , template )
220220 if err != nil {
221221 return nil , nil , fmt .Errorf (`failed to create temporary file: %w` , err )
222222 }
@@ -277,7 +277,7 @@ func DecryptJweFile(ctx context.Context, file string, alg jwa.KeyEncryptionAlgor
277277 return jwe .Decrypt (buf , jwe .WithKey (alg , rawkey ))
278278}
279279
280- func EncryptJweFile (ctx context.Context , payload []byte , keyalg jwa.KeyEncryptionAlgorithm , keyfile string , contentalg jwa.ContentEncryptionAlgorithm , compressalg jwa.CompressionAlgorithm ) (string , func (), error ) {
280+ func EncryptJweFile (ctx context.Context , dir string , payload []byte , keyalg jwa.KeyEncryptionAlgorithm , keyfile string , contentalg jwa.ContentEncryptionAlgorithm , compressalg jwa.CompressionAlgorithm ) (string , func (), error ) {
281281 key , err := ParseJwkFile (ctx , keyfile )
282282 if err != nil {
283283 return "" , nil , fmt .Errorf (`failed to parse keyfile %s: %w` , keyfile , err )
@@ -311,7 +311,7 @@ func EncryptJweFile(ctx context.Context, payload []byte, keyalg jwa.KeyEncryptio
311311 return "" , nil , fmt .Errorf (`failed to encrypt payload: %w` , err )
312312 }
313313
314- return WriteFile ("jwx-test-*.jwe" , bytes .NewReader (buf ))
314+ return WriteFile (dir , "jwx-test-*.jwe" , bytes .NewReader (buf ))
315315}
316316
317317func VerifyJwsFile (ctx context.Context , file string , alg jwa.SignatureAlgorithm , jwkfile string ) ([]byte , error ) {
@@ -342,7 +342,7 @@ func VerifyJwsFile(ctx context.Context, file string, alg jwa.SignatureAlgorithm,
342342 return jws .Verify (buf , jws .WithKey (alg , pubkey ))
343343}
344344
345- func SignJwsFile (ctx context.Context , payload []byte , alg jwa.SignatureAlgorithm , keyfile string ) (string , func (), error ) {
345+ func SignJwsFile (ctx context.Context , dir string , payload []byte , alg jwa.SignatureAlgorithm , keyfile string ) (string , func (), error ) {
346346 key , err := ParseJwkFile (ctx , keyfile )
347347 if err != nil {
348348 return "" , nil , fmt .Errorf (`failed to parse keyfile %s: %w` , keyfile , err )
@@ -353,5 +353,5 @@ func SignJwsFile(ctx context.Context, payload []byte, alg jwa.SignatureAlgorithm
353353 return "" , nil , fmt .Errorf (`failed to sign payload: %w` , err )
354354 }
355355
356- return WriteFile ("jwx-test-*.jws" , bytes .NewReader (buf ))
356+ return WriteFile (dir , "jwx-test-*.jws" , bytes .NewReader (buf ))
357357}
0 commit comments