[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bouncycastle-crypto-dev
Subject:    Re: [dev-crypto] Re: Tell P7M and P7S apart
From:       Giacomo Boccardo <gboccardo () unimaticaspa ! it>
Date:       2017-06-05 20:06:06
Message-ID: 1dHyGM-0000ii-Q1 () unimaticaspa ! it
[Download RAW message or body]

On 06/05/17 15:06:45, Peter Dettman wrote:
> Hi Giacomo,
Hi Peter,
>
> There's no reason it shouldn't work with definite lengths I assume you
> are seeing the "corrupted stream" exception because you are only passing
> in the beginning of the file, or fiddling with the stream in some other way.
That's exactly the reason.
> In any case, to avoid the bounds checking, you can use:
> 	new ASN1StreamParser(seqStream, Integer.MAX_VALUE);
>
> I suppose the code I gave is not strictly the minimum number of bytes
> possible, since it will read the tag and length of the 'content' tagged
> object, when in theory you only need to read (or not) the first byte of
> its tag.
> If somehow those extra few bytes are important, you might need to copy
> some of the internal code and adapt it to the bare minimum.
A few extra bytes are not a problem: I simply need not to read all the 
content just to test if it's present :)
If it works like that, it's surely better than reading it as I did.
>
> Regards,
> Pete Dettman
>
Kind regards,
     Giacomo
> On 5/06/2017 2:56 AM, Giacomo Boccardo wrote:
>> Hi Peter,
>>
>>      thanks for your solution, but unfortunately I've already tried that
>> and it doesn't work if you have definite lengths.
>>
>> I have many
>>
>> java.io.IOException: corrupted stream - out of bounds length found
>>
>> on the second instruction because
>>
>> int length = ASN1InputStream.readLength(_in, _limit);
>>
>> is called and if you don't have enough bytes on the stream it raises
>> that exception.
>>
>> If I pass all the stream it works, but I should investigate further to
>> be sure that all those calls are really lazy: I need a quick detection
>> using as few bytes as possible.
>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic