Test case change to reflect accurate assertion for Elliptic Curve 'd' values against the curve order (not the field size) per https://datatracker.ietf.org/doc/html/rfc7518#section-6.2.2.1 (#906)

This commit is contained in:
lhazlewood 2024-01-26 17:54:51 -08:00 committed by GitHub
parent fd619e0a42
commit f61cfa875d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 4 deletions

View File

@ -63,14 +63,18 @@ class AbstractEcJwkFactoryTest {
def y = Decoders.BASE64URL.decode(ys) def y = Decoders.BASE64URL.decode(ys)
def d = Decoders.BASE64URL.decode(ds) def d = Decoders.BASE64URL.decode(ds)
// most important part of the test: the decoded byte arrays must have a length equal to the curve // most important part of the test: 'x' and 'y' decoded byte arrays must have a length equal to the curve
// field size (in bytes): // field size (in bytes) per https://datatracker.ietf.org/doc/html/rfc7518#section-6.2.1.2 and
// https://datatracker.ietf.org/doc/html/rfc7518#section-6.2.1.3
int fieldSizeInBits = key.getParams().getCurve().getField().getFieldSize() int fieldSizeInBits = key.getParams().getCurve().getField().getFieldSize()
int fieldSizeInBytes = Bytes.length(fieldSizeInBits) int fieldSizeInBytes = Bytes.length(fieldSizeInBits)
assertEquals fieldSizeInBytes, x.length assertEquals fieldSizeInBytes, x.length
assertEquals fieldSizeInBytes, y.length assertEquals fieldSizeInBytes, y.length
assertEquals fieldSizeInBytes, d.length
// and 'd' must have a length equal to the curve order size in bytes per
// https://datatracker.ietf.org/doc/html/rfc7518#section-6.2.2.1
int orderSizeInBytes = Bytes.length(key.params.order.bitLength())
assertEquals orderSizeInBytes, d.length
} }
} }
} }