bc-csharp icon indicating copy to clipboard operation
bc-csharp copied to clipboard

Warning using Bouncy Castle v.2.3.0

Open slumdroid opened this issue 1 year ago • 3 comments

Hello,

using Bouncy Castle v.2.3.0, I have the following warning: 'Asn1TaggedObject.GetObject()' is obsolete: 'Will be removed'

Can you indicate me the new method to use instead it, please?

slumdroid avatar Feb 05 '24 15:02 slumdroid

In this moment, I am trying "Asn1TaggedObject.GetBaseObject()". And in my first tests, I have not failures.

Is this the correct solution?

slumdroid avatar Feb 05 '24 16:02 slumdroid

A direct drop-in for:

Asn1Object asn1Object = taggedObject.GetObject();

would be:

Asn1Utilities.CheckContextTagClass(taggedObject);
Asn1Object asn1Object = taggedObject.GetBaseObject().ToAsn1Object();

which is basically just inlining the current implementation. CheckContextTagClass can throw, so you might prefer to test taggedObject.HasContextTag() instead.

I would suggest though that you provide a little detail about the call, in particular what your code is expecting to find (i.e. is there a cast or GetInstance call for the return value?) and/or the ASN.1 datatype of which this tagged object is a member (e.g. is it a named type from some RFC?). Direct usage of GetObject() has historically been very error prone in user code.

peterdettman avatar Feb 06 '24 05:02 peterdettman

A direct drop-in for:

Asn1Object asn1Object = taggedObject.GetObject();

would be:

Asn1Utilities.CheckContextTagClass(taggedObject);
Asn1Object asn1Object = taggedObject.GetBaseObject().ToAsn1Object();

which is basically just inlining the current implementation. CheckContextTagClass can throw, so you might prefer to test taggedObject.HasContextTag() instead.

I would suggest though that you provide a little detail about the call, in particular what your code is expecting to find (i.e. is there a cast or GetInstance call for the return value?) and/or the ASN.1 datatype of which this tagged object is a member (e.g. is it a named type from some RFC?). Direct usage of GetObject() has historically been very error prone in user code.

Dear @peterdettman,

thanks for your reply. I use the cast (Asn1Sequence and Asn1OctectString for different scopes) into my source code.

slumdroid avatar Feb 06 '24 07:02 slumdroid