@@ -135,8 +135,8 @@ func GenerateX25519Jwk() (jwk.Key, error) {
135135 return k , nil
136136}
137137
138- func WriteFile (template string , src io.Reader ) (string , func (), error ) {
139- file , cleanup , err := CreateTempFile (template )
138+ func WriteFile (dir , template string , src io.Reader ) (string , func (), error ) {
139+ file , cleanup , err := CreateTempFile (dir , template )
140140 if err != nil {
141141 return "" , nil , fmt .Errorf (`failed to create temporary file: %w` , err )
142142 }
@@ -153,14 +153,14 @@ func WriteFile(template string, src io.Reader) (string, func(), error) {
153153 return file .Name (), cleanup , nil
154154}
155155
156- func WriteJSONFile (template string , v interface {}) (string , func (), error ) {
156+ func WriteJSONFile (dir , template string , v interface {}) (string , func (), error ) {
157157 var buf bytes.Buffer
158158
159159 enc := json .NewEncoder (& buf )
160160 if err := enc .Encode (v ); err != nil {
161161 return "" , nil , fmt .Errorf (`failed to encode object to JSON: %w` , err )
162162 }
163- return WriteFile (template , & buf )
163+ return WriteFile (dir , template , & buf )
164164}
165165
166166func DumpFile (t * testing.T , file string ) {
@@ -206,8 +206,8 @@ func DumpFile(t *testing.T, file string) {
206206 t .Logf ("=== END %s (formatted JSON) ===" , file )
207207}
208208
209- func CreateTempFile (template string ) (* os.File , func (), error ) {
210- file , err := os .CreateTemp ("" , template )
209+ func CreateTempFile (dir , template string ) (* os.File , func (), error ) {
210+ file , err := os .CreateTemp (dir , template )
211211 if err != nil {
212212 return nil , nil , fmt .Errorf (`failed to create temporary file: %w` , err )
213213 }
@@ -268,7 +268,7 @@ func DecryptJweFile(ctx context.Context, file string, alg jwa.KeyEncryptionAlgor
268268 return jwe .Decrypt (buf , jwe .WithKey (alg , rawkey ))
269269}
270270
271- func EncryptJweFile (ctx context.Context , payload []byte , keyalg jwa.KeyEncryptionAlgorithm , keyfile string , contentalg jwa.ContentEncryptionAlgorithm , compressalg jwa.CompressionAlgorithm ) (string , func (), error ) {
271+ func EncryptJweFile (ctx context.Context , dir string , payload []byte , keyalg jwa.KeyEncryptionAlgorithm , keyfile string , contentalg jwa.ContentEncryptionAlgorithm , compressalg jwa.CompressionAlgorithm ) (string , func (), error ) {
272272 key , err := ParseJwkFile (ctx , keyfile )
273273 if err != nil {
274274 return "" , nil , fmt .Errorf (`failed to parse keyfile %s: %w` , keyfile , err )
@@ -302,7 +302,7 @@ func EncryptJweFile(ctx context.Context, payload []byte, keyalg jwa.KeyEncryptio
302302 return "" , nil , fmt .Errorf (`failed to encrypt payload: %w` , err )
303303 }
304304
305- return WriteFile ("jwx-test-*.jwe" , bytes .NewReader (buf ))
305+ return WriteFile (dir , "jwx-test-*.jwe" , bytes .NewReader (buf ))
306306}
307307
308308func VerifyJwsFile (ctx context.Context , file string , alg jwa.SignatureAlgorithm , jwkfile string ) ([]byte , error ) {
@@ -333,7 +333,7 @@ func VerifyJwsFile(ctx context.Context, file string, alg jwa.SignatureAlgorithm,
333333 return jws .Verify (buf , jws .WithKey (alg , pubkey ))
334334}
335335
336- func SignJwsFile (ctx context.Context , payload []byte , alg jwa.SignatureAlgorithm , keyfile string ) (string , func (), error ) {
336+ func SignJwsFile (ctx context.Context , dir string , payload []byte , alg jwa.SignatureAlgorithm , keyfile string ) (string , func (), error ) {
337337 key , err := ParseJwkFile (ctx , keyfile )
338338 if err != nil {
339339 return "" , nil , fmt .Errorf (`failed to parse keyfile %s: %w` , keyfile , err )
@@ -344,5 +344,5 @@ func SignJwsFile(ctx context.Context, payload []byte, alg jwa.SignatureAlgorithm
344344 return "" , nil , fmt .Errorf (`failed to sign payload: %w` , err )
345345 }
346346
347- return WriteFile ("jwx-test-*.jws" , bytes .NewReader (buf ))
347+ return WriteFile (dir , "jwx-test-*.jws" , bytes .NewReader (buf ))
348348}
0 commit comments