From: Doug E. <no...@gi...> - 2020-11-25 07:50:52
|
Branch: refs/heads/master Home: https://github.com/OpenSC/OpenSC Commit: 483e1531825d539d2faa8b6445b81b749be6acde https://github.com/OpenSC/OpenSC/commit/483e1531825d539d2faa8b6445b81b749be6acde Author: Doug Engert <dee...@gm...> Date: 2020-11-25 (Wed, 25 Nov 2020) Changed paths: M src/libopensc/asn1.h Log Message: ----------- ASN1 cleanup part 1 ASN1 tags are represented in two many ways within OpenSC. This is a trivial change to simplify one aspect of this. It also makes the code more readable. SC_ASN1_CLASS_MASK, SC_ASN1_APP, SC_ASN1_CTX, SC_ASN1_PRV, SC_ASN1_CONS are changed, and SC_ASN1_CLASS_MASK is added. These then align with the bits defined by SC_ASN1_TAG_CLASS, SC_ASN1_TAG_APPLICATION, SC_ASN1_TAG_CONTEXT, SC_ASN1_TAG_PRIVATE, and SC_ASN1_TAG_CONSTRUCTED. (SC_ASN1_UNI and SC_ASN1_TAG_UNIVERSAL are both 0x00 thus no change is needed). (No sign of a right shift of SC_ASN1_CTX or SC_ASN1_PRV causeing problems has been seen in the code.) If found, can be solved.) Close examination of the OpenSC code base shows all uses of tags used by routines and sc_asn1_entry use the defines. This could allows 26 lines of code in sc_asn1_skip_tag used to test the 3 CLASS and CONSTRUCTED bits to be replaced by: if (((cla << 24) | tag) != tag_in) return NULL; The 26 lines still work as will any other code in OpenSC that tests the bits using the defines. It also allows new code to be simplified. Problem identified while looking at better way to check response on GET_DATA (0xCB) that returns TLV as used in card-piv.c Changes tested using pkcs11-tool --test --login with PIV, SC_HSM and OpenPGP cards. |