Re: [pyasn1-users] Asn1Item.hasValue()/.isValue
Brought to you by:
elie
From: Ilya E. <il...@gl...> - 2017-04-09 11:11:14
|
Hi Sergey, Thank you for testing the master branch! That looks like a nuisance — although .hasValue() is obsolete, it should be supported alongside with .isValue. I’ve just fixed that in master (b8085ece44a9c8eaf63b803b82b0a281e95357c4). Let me know if you experience any issues with it! The logic behind .isValue / .hasValue() is that they let you know if the object has a payload (isValue == True) or is just an empty container which could be used for guiding decoder. If you are looking for a way to figure out which SET components are optional, you should probably use: sd.componentType[‘certificates’].isOptional Thanks! > On 9 Apr 2017, at 12:51, Sergey Matveev <sta...@st...> wrote: > > Greetings! > > *** Ilya Etingof <il...@gl...> [2017-04-06 16:11]: >> With the first example, the same check for object initialization state >> could be done by testing its `.isValue` property: >> >> akid['authorityCertIssuer'].isValue >> >> or `.hasValue()` function (which is backward compatible). > > Do I clearly understand that with those example CMS-related structures: > > class SignedData(Sequence): > componentType = NamedTypes( > NamedType('version', CMSVersion()), > NamedType('digestAlgorithms', DigestAlgorithmIdentifiers()), > NamedType('encapContentInfo', EncapsulatedContentInfo()), > OptionalNamedType('certificates', CertificateSet().subtype( > implicitTag=Tag(tagClassContext, tagFormatSimple, 0) > )), > [...] > ) > > class CertificateSet(SetOf): > componentType = CertificateChoices() > > class CertificateChoices(Choice): > componentType = NamedTypes( > NamedType('certificate', Certificate()), > [...] > ) > > that kind of "certificates" optional field existence check should pass, > but has troubles with hasValue()?: > >>>> sd = SignedData() >>>> sd['certificates'].isValue > False >>>> sd['certificates'].hasValue() > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > AttributeError: 'CertificateSet' object has no attribute 'hasValue' > > -- > Sergey Matveev (http://www.stargrave.org/) > OpenPGP: CF60 E89A 5923 1E76 E263 6422 AE1A 8109 E498 57EF > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > pyasn1-users mailing list > pya...@li... > https://lists.sourceforge.net/lists/listinfo/pyasn1-users |