Including uninitialized, optional, SetOf?
Hi,
After https://github.com/etingof/pyasn1/commit/6fa0e312ea80713983b1a3c1e4529e7452b0e0fe I observe that an uninitialized, and optional, SetOf is being included in the encoded data.
In my case it's a PrivateKeyInfo structure (https://github.com/etingof/pyasn1-modules/blob/master/pyasn1_modules/rfc5208.py#L49) and before the change the attributes was not being included:
0:d=0 hl=4 l=1213 cons: SEQUENCE
4:d=1 hl=2 l= 1 prim: INTEGER :00
7:d=1 hl=2 l= 13 cons: SEQUENCE
9:d=2 hl=2 l= 9 prim: OBJECT :rsaEncryption
20:d=2 hl=2 l= 0 prim: NULL
22:d=1 hl=4 l=1191 prim: OCTET STRING [HEX DUMP]:308204A3...
But after they are:
0:d=0 hl=4 l=1215 cons: SEQUENCE
4:d=1 hl=2 l= 1 prim: INTEGER :00
7:d=1 hl=2 l= 13 cons: SEQUENCE
9:d=2 hl=2 l= 9 prim: OBJECT :rsaEncryption
20:d=2 hl=2 l= 0 prim: NULL
22:d=1 hl=4 l=1191 prim: OCTET STRING [HEX DUMP]:308204A...
1217:d=1 hl=2 l= 0 cons: cont [ 0 ]
I can get rid of it if I include attributes with an empty attribute, but it seems weird to me that I have to.
Is this how it's supposed to be? Thanks.
Any change for a update here?
@etingof Hello, this issue is causing an active breakage for my project. Is there any way this could get attention soon?
@magnuswatn do you mind sharing an example for your "include attributes with an empty attribute" workaround?
@ashafer01 See https://github.com/magnuswatn/pyjks/commit/3b15250a31079550cf4a73cb43547c33624dc7d6
This also works: https://github.com/magnuswatn/pyjks/commit/76f28c75b95e99b216be15c0043c3101891c983d
Oh,I somehow managed to overlook this issue, sorry for that!
I think the second solution offered by @magnuswatn is the good one:
encoder.encode(private_key_info, ifNotEmpty=True)
Does it solve your issue?
Thanks for getting back! When I tried with ifNotEmpty=True I got a ton of protocol errors from my test servers, looks like a no-go for my use case. I haven't yet tried the empty attribute method.
Just to be clear @etingof: You're saying that pyasn1 works as intended here, and the we should use ifNotEmpty=True, to get rid of the extra attributes? Thanks.