From fddc2c80dea8f7ad03f85203d818fcc0eb4bcfa7 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 4 Mar 2015 02:08:57 +0000 Subject: When comparing algorithm identifiers consider NULL and empty parameters as equivalent. Based on a patch sent to the mailing list by Uri Blumenthal. --- doc/relnotes/1_11_15.rst | 4 ++++ src/lib/asn1/alg_id.cpp | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/doc/relnotes/1_11_15.rst b/doc/relnotes/1_11_15.rst index 4c47785df..a0937deb2 100644 --- a/doc/relnotes/1_11_15.rst +++ b/doc/relnotes/1_11_15.rst @@ -3,3 +3,7 @@ Version 1.11.15, Not Yet Released * A bug in ffi.cpp meant Python could only encrypt. Github issue 53. +* When comparing two ASN.1 algorithm identifiers, consider empty and + NULL parameters the same. + +* Fix compilation problem on OS X diff --git a/src/lib/asn1/alg_id.cpp b/src/lib/asn1/alg_id.cpp index 8e6651d52..7d476a225 100644 --- a/src/lib/asn1/alg_id.cpp +++ b/src/lib/asn1/alg_id.cpp @@ -63,13 +63,27 @@ AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id, /* * Compare two AlgorithmIdentifiers */ +namespace { + +bool param_null_or_empty(const std::vector& p) + { + if(p.size() == 2 && (p[0] == 0x05) && (p[1] == 0x00)) + return true; + return p.empty(); + } + +} + bool operator==(const AlgorithmIdentifier& a1, const AlgorithmIdentifier& a2) { if(a1.oid != a2.oid) return false; - if(a1.parameters != a2.parameters) - return false; - return true; + + if(param_null_or_empty(a1.parameters) && + param_null_or_empty(a2.parameters)) + return true; + + return (a1.parameters == a2.parameters); } /* -- cgit v1.2.3