Open vancejc-mt opened 4 months ago
This needs to be documented better, The reserve_size IS the is the size of the fiinal CoseSign1 cbor (not anything to do with DER). The reserve_size must be large enough the cover the completed size. Any extra space is absorbed by the padding fields in the CoseSign1. If the cbor ends up too big you will get a box too small error
To calc the reserve_size you must account for the size of [chain chain + timestamp response + OCSP response + size of Claim cbor]
Understood - this was referencing what I believe to be a bug though. If the reserve size is larger than the size needed for the CoseSign1
cbor, but only by a small amount, the padding calculation in the SDK I think is incorrect. It ends up adding too much padding which then causes a CoseSigboxTooSmall
error. It seems he's not correctly taking into account (or maybe incorrectly calculating) that adding padding requires the variable size integer which describes the padding size.
I will take a look
Still curious why someone would try to get within 7 bytes of the limit. Also the DER encoding has to be accounted for by the Signer not us.
We were trying to get the size down as small as possible when we ran into this - we ended up backing off and adding more padding, but thought this may be interesting as an issue.
If the reserve size returned by
AsyncSigner::reserve_size()
is fairly close (but not exact) to the size of theCose_Sign1
structure whichc2pa-rs
generates, we're seeingCoseSigboxTooSmall
errors be returned.The behavior of this is somewhat weird, and I believe it's because the padding calculation (
let mut target_guess = end_size - cur_size - PAD_OFFSET
) doesn't accurately account for the size which the header itself will take up once it's DER encoded. Thus it calculates a pad which is too large which then causes the reserve size to be overwhelmed.I don't believe this should ever be the case - if the reserve size is larger than the size of the eventual
Cose_Sign1
structure, this should succeed.Maybe this is an understanding on my part? But to get this to work correctly, we're having to add in overly big reserve sizes to avoid the issue.