The code is correct - it's more an issue of the way the dump class
works. Unfortunately (or fortunately depending on which side of the line
you're on) an implicitly tagged object doesn't represent a specific type
clearly as if it's a sequence or a set the object is tagged as
constructed, which is also used as the flag to indicate in BER/DER that
an object is explicitly tagged.
The BC dump command is able to guess that the object is implicit because
it is tagged as constructed and there is more than one element in it
(try an implicit set with a single object and you'll see what I mean).
It shows the type as sequence as a sequence is used as the carrying type
(the reasons for this date back quite a few years...) to hold the
elements until the real type can be resolved.
So the answer is that the dump command has to guess when it sees a
tagged object, so it guess's a sequence. I'll probably change this as it
can obviously be confusing if you're not familiar with what's going on,
but there will still be issues with constructed primitives with only one
member element - they'll almost never be distinguished properly
(explicitly tagged sets and sequences excepted), it's not possible to do
so unless you really know the context.
Or put another way, seeing a tag on an object in a BER/DER stream is
like seeing an indicator light flashing on a car - it means the globe is
working. Whether the driver turns or not is still for later discovery.
In the same way, without explicit knowledge of the ASN.1 structure being
parsed, a tagged object is just that...
Regards,
David
On Wed, 2009-10-21 at 17:06 +0200, Lothar Kimmeringer wrote:
> public class DERSetTest {
>
> public final static void main(String[] args) throws Exception{
> ASN1EncodableVector vec = new ASN1EncodableVector();
> vec.add(new DERInteger(1));
> vec.add(new DERInteger(2));
> vec.add(new DERInteger(3));
> DERSet set = new DERSet(vec);
> DERTaggedObject tag = new DERTaggedObject(false, 1, set);
>
> byte[] encoded = tag.getDEREncoded();
>
> System.out.println(ASN1Dump.dumpAsString(new ASN1InputStream(encoded).readObject()));
> }
> }
>
> When executing I get
>
> Tagged [1] IMPLICIT
> DER Sequence
> Integer(1)
> Integer(2)
> Integer(3)
>
> Is it impossible to do this (then why is it used e.g. in X.228)
> or is there something wrong with the encoding of such a structure?
>
>
> Regards, Lothar
>