Skip to content

Commit

Permalink
Merge pull request lestrrat-go#272 from lestrrat-go/topic/deadcode
Browse files Browse the repository at this point in the history
remove commented out, dead code
  • Loading branch information
lestrrat authored Jan 10, 2021
2 parents f502fde + ba4f653 commit d5adbdd
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 166 deletions.
8 changes: 0 additions & 8 deletions jwe/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,3 @@ func (d *Decrypter) BuildKeyDecrypter() (keyenc.Decrypter, error) {
return nil, errors.Errorf(`unsupported algorithm for key decryption (%s)`, alg)
}
}

/*
buildKeyDecrypter(d.keyalg, h2, d.privkey, cipher.KeySize())
func buildECDHESDecrypter(alg jwa.KeyEncryptionAlgorithm, h Headers, key interface{}) (keyenc.Decrypter, error) {
}
*/
77 changes: 0 additions & 77 deletions jwe/jwe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,83 +637,6 @@ func TestDecodePredefined_Direct(t *testing.T) {
}
}

/*
XXX If I'm reading this right, when a message is encrypted, the exact output
depends on the JSON serialization format of the data, including things like
the protected header. So if the protected header contained something like
map[string]interface{}{
"a": 1,
"b": 2,
}
and for different implementations the serializers serialized the above as
{"a":1,"b":2}
{"b":2,"a":1}
Things like the the cipher tag would differ, even though the values are
technically the same.
below tests were stolen directly from the go-jose test suite, but I believe
the tags used here are specific to their serialization format, and not mine
func TestGoJoseCompatibility(t *testing.T) {
t.Run("TestPrecomputedECDHMessagesFromJose4j", func(t *testing.T) {
data := []struct{ key, message string }{
{
`{"kty":"EC","x":"fXx-DfOsmecjKh3VrLZFsF98Z1nutsL4UdFTdgA8S7Y","y":"LGzyJY99aqKk52UIExcNFSTs0S7HnNzQ-DRWBTHDad4","crv":"P-256","d":"OeVCWbXuFuJ9U16q7bhLNoKPLLnK-yTx95grzfvQ2l4"}`,
`eyJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwiYWxnIjoiRUNESC1FUyIsImVwayI6eyJrdHkiOiJFQyIsIngiOiJ3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e2BaxZmJQ016GY-U7NV_EWhrPsLDC5l9tAM9DGEwI2cT2HcO20Z6CQndw0ZhqLZ6MEvS8siL-SCxIl2"}`,
`eyJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwiYWxnIjoiRUNESC1FUyIsImVwayI6eyJrdHkiOiJFQyIsIngiOiJBQ1RLMlVPSjJ6SVk3U1U4T0xkaG1QQmE4ZUVpd2JrX09UMXE0MHBsRlRwQmJKUXg3YWdqWG9LYml2NS1OTXB6eXZySm1rblM3SjNRUWlUeFgwWmtjemhEIiwieSI6IkFXeTZCR1dkZld2ekVNeGIxQklCQnZmRDJ4bEh6Rjk2YzVVRVQ4SFBUS0RSeUJyMnQ4T2dTX1J2MnNoUmxGbXlqUWpyX25uQk94akcxVTZNWDNlZ2VETzciLCJjcnYiOiJQLTUyMSJ9fQ..EWqSGntxbO_Y_6JRjFkCgg.DGjDNjAYdsnYTpUFJi1gEI4YtNd7gBPMjD3CDH047RAwZKTme6Ah_ztzxSfVg5kG.yGm5jn2LtbFXaK_yf0b0932sI2O77j2gwmL1Y09YC_Y`,
},
}
for i, vector := range data {
vector := vector
t.Run(fmt.Sprintf("Dataset %d", i), func(t *testing.T) {
webkey, err := jwk.ParseKey([]byte(vector.key))
if !assert.NoError(t, err, `jwk.ParseKey should succeed`) {
return
}
{
buf, _ := json.MarshalIndent(webkey, "", " ")
t.Logf("%s", buf)
}
parsed, err := jwe.ParseString(vector.message)
if !assert.NoError(t, err, `jwe.ParseString should succeed`) {
return
}
{
buf, _ := json.MarshalIndent(parsed, "", " ")
t.Logf("%s", buf)
}
var key ecdsa.PrivateKey
if !assert.NoError(t, webkey.Raw(&key), `webkey.Raw should succeed`) {
return
}
_, err = parsed.Decrypt(((parsed.Recipients())[0]).Headers().Algorithm(), &key)
if !assert.NoError(t, err, `Decrypt should succeed`) {
return
}
})
}
})
}
*/

func TestGHIssue230(t *testing.T) {
t.Parallel()

Expand Down
51 changes: 0 additions & 51 deletions jws/jws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,51 +933,6 @@ func TestEncode(t *testing.T) {
})
}

/*
func TestSign_HeaderValues(t *testing.T) {
const jwksrc = `{
"kty":"EC",
"crv":"P-256",
"x":"f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU",
"y":"x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0",
"d":"jpsQnnGQmL-YBIffH1136cspYG6-0iY7X1fCE9-E9LI"
}`
privkey, err := ecdsautil.PrivateKeyFromJSON([]byte(jwksrc))
if !assert.NoError(t, err, "parsing jwk should be successful") {
return
}
payload := []byte("Hello, World!")
hdr := jws.NewHeader()
hdr.KeyID = "helloworld01"
encoded, err := jws.Sign(payload, jwa.ES256, privkey, jws.WithPublicHeaders(hdr))
if !assert.NoError(t, err, "Sign should succeed") {
return
}
// Although we set KeyID to the public header, in compact serialization
// there's no difference
msg, err := jws.Parse(bytes.NewReader(encoded))
if !assert.NoError(t, err, `parse should succeed`) {
return
}
if !assert.Equal(t, hdr.KeyID, msg.Signatures[0].ProtectedHeader.KeyID, "KeyID should match") {
return
}
verified, err := jws.Verify(encoded, jwa.ES256, &privkey.PublicKey)
if !assert.NoError(t, err, "Verify should succeed") {
return
}
if !assert.Equal(t, verified, payload, "Payload should match") {
return
}
}
*/

func TestPublicHeaders(t *testing.T) {
key, err := jwxtest.GenerateRsaKey()
if !assert.NoError(t, err, "GenerateKey should succeed") {
Expand All @@ -996,12 +951,6 @@ func TestPublicHeaders(t *testing.T) {
return
}
_ = pubjwk // TODO

/*
if !assert.NoError(t, signer.UnprotectedHeaders().Set("jwk", pubjwk), "Set('jwk') should succeed") {
return
}
*/
}

func TestDecode_ES384Compact_NoSigTrim(t *testing.T) {
Expand Down
30 changes: 0 additions & 30 deletions jwt/internal/cmd/gentoken/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,36 +576,6 @@ func generateToken(tt tokenType) error {
fmt.Fprintf(&buf, "\n}")
fmt.Fprintf(&buf, "\n}")
fmt.Fprintf(&buf, "\n}") // end of (h *stdHeaders) iterate(...)
/*
switch {
case field.IsList():
fmt.Fprintf(&buf, "\n\nfunc (t *%s) %s() %s {", tt.structName, field.method, field.typ)
fmt.Fprintf(&buf, "\nif v, ok := t.Get(%sKey); ok {", field.method)
fmt.Fprintf(&buf, "\nreturn v.([]string)")
fmt.Fprintf(&buf, "\n}") // end if v, ok := t.Get(%sKey)
fmt.Fprintf(&buf, "\nreturn nil")
fmt.Fprintf(&buf, "\n}") // end func (t stdToken) %s() %s
case field.typ == "*types.NumericDate":
fmt.Fprintf(&buf, "\n\nfunc (t *%s) %s() time.Time {", tt.structName, field.method)
fmt.Fprintf(&buf, "\nif v, ok := t.Get(%sKey); ok {", field.method)
fmt.Fprintf(&buf, "\nreturn v.(time.Time)")
fmt.Fprintf(&buf, "\n}")
fmt.Fprintf(&buf, "\nreturn time.Time{}")
fmt.Fprintf(&buf, "\n}") // end func (t Token) %s()
case field.IsPointer():
fmt.Fprintf(&buf, "\n\n// %s is a convenience function to retrieve the corresponding value store in the token", field.method)
fmt.Fprintf(&buf, "\n// if there is a problem retrieving the value, the zero value is returned. If you need to differentiate between existing/non-existing values, use `Get` instead")
fmt.Fprintf(&buf, "\n\nfunc (t *%s) %s() %s {", tt.structName, field.method, field.PointerElem())
fmt.Fprintf(&buf, "\nif v, ok := t.Get(%sKey); ok {", field.method)
fmt.Fprintf(&buf, "\nreturn v.(%s)", field.PointerElem())
fmt.Fprintf(&buf, "\n}") // end if v, ok := t.Get(%sKey)
fmt.Fprintf(&buf, "\nreturn %s", zeroval(field.PointerElem()))
fmt.Fprintf(&buf, "\n}") // end func (t Token) %s() %s
}
}
*/

// JSON related stuff
fmt.Fprintf(&buf, "\n\nfunc (t *%s) UnmarshalJSON(buf []byte) error {", tt.structName)
Expand Down

0 comments on commit d5adbdd

Please sign in to comment.