forked from lestrrat-go/jwx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request lestrrat-go#190 from lestrrat-go/topic/coverage
Play the coverage game, take 3
- Loading branch information
Showing
25 changed files
with
1,046 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package jwe | ||
|
||
import ( | ||
"bytes" | ||
"compress/flate" | ||
"io/ioutil" | ||
|
||
"github.com/lestrrat-go/jwx/jwa" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func uncompress(plaintext []byte) ([]byte, error) { | ||
return ioutil.ReadAll(flate.NewReader(bytes.NewReader(plaintext))) | ||
} | ||
|
||
func compress(plaintext []byte, alg jwa.CompressionAlgorithm) ([]byte, error) { | ||
if alg == jwa.NoCompress { | ||
return plaintext, nil | ||
} | ||
|
||
var output bytes.Buffer | ||
w, _ := flate.NewWriter(&output, 1) | ||
in := plaintext | ||
for len(in) > 0 { | ||
n, err := w.Write(in) | ||
if err != nil { | ||
return nil, errors.Wrap(err, `failed to write to compression writer`) | ||
} | ||
in = in[n:] | ||
} | ||
if err := w.Close(); err != nil { | ||
return nil, errors.Wrap(err, "failed to close compression writer") | ||
} | ||
return output.Bytes(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.