edk2toollib/uefi/authenticated_variables_structure_support.py
def GetCanonicalAndDupes(self):
        """
        Compute and return a tuple containing both a canonicalized database & a database of duplicates

        Returns -> (canonical: EfiSignatureDatabase, duplicates: EfiSignatureDatabase)
        canonical is an EfiSignatureDatabase where EfiSignatureLists are merged (where possible),
            deduplicated, & sorted, and the EfiSignatureData elements are also deduplicated & sorted
        duplicates is an EfiSignatureDatabase with EfiSignatureLists containing any duplicated
            EfiSignatureData entries (only the data contents are checked for effective equality,
            signature owner is ignored)
        """

        # First group EFI_SIGNATURE_LISTS by type, merging them where possible

        sha256esl = None
        x509eslList = None

        for Esl in self.EslList:
            if(Esl.SignatureData_List is None):  # discard empty EfiSignatureLists
                continue
            if(Esl.SignatureType == EfiSignatureDataFactory.EFI_CERT_SHA256_GUID):
                if(sha256esl is None):
                    sha256esl = Esl  # initialize it
                else:
                    sha256esl.MergeSignatureList(Esl)
            elif(Esl.SignatureType == EfiSignatureDataFactory.EFI_CERT_X509_GUID):
                if(x509eslList is None):
                    x509eslList = [Esl]  # initialize it
                else:
                    x509eslList.append(Esl)
            else:
                raise Exception("Unsupported signature type %s", Esl.SignatureType)

        # for each type, sort and de-duplicate, and then populate the respective databases
        # note the ordering of this section is the prescribed canonical order
        # first 1 EfiSignatureList for SHA256 hashes, EfiSignatureData elements sorted ascending
        # followed by EfiSignatureLists for each x509 certificate, sorted ascending by data content

        canonicalDb = EfiSignatureDatabase()
        duplicatesDb = EfiSignatureDatabase()

        if(sha256esl is not None):
            dupes = sha256esl.SortBySignatureDataValue(deduplicate=True)
            canonicalDb.EslList.append(sha256esl)
            duplicatesDb.EslList.append(dupes)

        if(x509eslList is not None):
            x509eslList.sort(key=attrgetter('SignatureData_List'))
            for esl in x509eslList:
                if not canonicalDb.EslList:
                    canonicalDb.EslList.append(esl)
                elif esl == canonicalDb.EslList[-1]:
                    duplicatesDb.EslList.append(esl)
                else:
                    canonicalDb.EslList.append(esl)

        return (canonicalDb, duplicatesDb)

        Compute and return a tuple containing both a canonicalized database & a database of duplicates

        Returns -> (canonical: EfiSignatureDatabase, duplicates: EfiSignatureDatabase)
        canonical is an EfiSignatureDatabase where EfiSignatureLists are merged (where possible),
            deduplicated, & sorted, and the EfiSignatureData elements are also deduplicated & sorted
        duplicates is an EfiSignatureDatabase with EfiSignatureLists containing any duplicated
            EfiSignatureData entries (only the data contents are checked for effective equality,
            signature owner is ignored)
        
Compute and return a tuple containing both a canonicalized database & a database of duplicates
Returns -> (canonical: EfiSignatureDatabase, duplicates: EfiSignatureDatabase)
canonical is an EfiSignatureDatabase where EfiSignatureLists are merged (where possible),
deduplicated, & sorted, and the EfiSignatureData elements are also deduplicated & sorted
duplicates is an EfiSignatureDatabase with EfiSignatureLists containing any duplicated
EfiSignatureData entries (only the data contents are checked for effective equality,
signature owner is ignored)
Compute and return a tuple containing both a canonicalized database & a database of duplicates Returns - > ( canonical : EfiSignatureDatabase duplicates : EfiSignatureDatabase ) canonical is an EfiSignatureDatabase where EfiSignatureLists are merged ( where possible ) deduplicated & sorted and the EfiSignatureData elements are also deduplicated & sorted duplicates is an EfiSignatureDatabase with EfiSignatureLists containing any duplicated EfiSignatureData entries ( only the data contents are checked for effective equality signature owner is ignored )
def GetCanonicalAndDupes(self):
        sha256esl = None
        x509eslList = None
        for Esl in self.EslList:
            if(Esl.SignatureData_List is None):  
                continue
            if(Esl.SignatureType == EfiSignatureDataFactory.EFI_CERT_SHA256_GUID):
                if(sha256esl is None):
                    sha256esl = Esl  
                else:
                    sha256esl.MergeSignatureList(Esl)
            elif(Esl.SignatureType == EfiSignatureDataFactory.EFI_CERT_X509_GUID):
                if(x509eslList is None):
                    x509eslList = [Esl]  
                else:
                    x509eslList.append(Esl)
            else:
                raise Exception("Unsupported signature type %s", Esl.SignatureType)
        canonicalDb = EfiSignatureDatabase()
        duplicatesDb = EfiSignatureDatabase()
        if(sha256esl is not None):
            dupes = sha256esl.SortBySignatureDataValue(deduplicate=True)
            canonicalDb.EslList.append(sha256esl)
            duplicatesDb.EslList.append(dupes)
        if(x509eslList is not None):
            x509eslList.sort(key=attrgetter('SignatureData_List'))
            for esl in x509eslList:
                if not canonicalDb.EslList:
                    canonicalDb.EslList.append(esl)
                elif esl == canonicalDb.EslList[-1]:
                    duplicatesDb.EslList.append(esl)
                else:
                    canonicalDb.EslList.append(esl)
        return (canonicalDb, duplicatesDb)
def GetCanonicalAndDupes ( self ) : sha256esl = None x509eslList = None for Esl in self . EslList : if ( Esl . SignatureData_List is None ) : continue if ( Esl . SignatureType == EfiSignatureDataFactory . EFI_CERT_SHA256_GUID ) : if ( sha256esl is None ) : sha256esl = Esl else : sha256esl . MergeSignatureList ( Esl ) elif ( Esl . SignatureType == EfiSignatureDataFactory . EFI_CERT_X509_GUID ) : if ( x509eslList is None ) : x509eslList = [ Esl ] else : x509eslList . append ( Esl ) else : raise Exception ( "Unsupported signature type %s" , Esl . SignatureType ) canonicalDb = EfiSignatureDatabase ( ) duplicatesDb = EfiSignatureDatabase ( ) if ( sha256esl is not None ) : dupes = sha256esl . SortBySignatureDataValue ( deduplicate = True ) canonicalDb . EslList . append ( sha256esl ) duplicatesDb . EslList . append ( dupes ) if ( x509eslList is not None ) : x509eslList . sort ( key = attrgetter ( 'SignatureData_List' ) ) for esl in x509eslList : if not canonicalDb . EslList : canonicalDb . EslList . append ( esl ) elif esl == canonicalDb . EslList [ - 1 ] : duplicatesDb . EslList . append ( esl ) else : canonicalDb . EslList . append ( esl ) return ( canonicalDb , duplicatesDb )
Compute and return a tuple containing both a canonicalized database & a database of duplicates
Returns -> (canonical: EfiSignatureDatabase, duplicates: EfiSignatureDatabase)
canonical is an EfiSignatureDatabase where EfiSignatureLists are merged (where possible),
deduplicated, & sorted, and the EfiSignatureData elements are also deduplicated & sorted
duplicates is an EfiSignatureDatabase with EfiSignatureLists containing any duplicated
EfiSignatureData entries (only the data contents are checked for effective equality,
signature owner is ignored)
Compute and return a tuple containing both a canonicalized database & a database of duplicates Returns - > ( canonical : EfiSignatureDatabase duplicates : EfiSignatureDatabase ) canonical is an EfiSignatureDatabase where EfiSignatureLists are merged ( where possible ) deduplicated & sorted and the EfiSignatureData elements are also deduplicated & sorted duplicates is an EfiSignatureDatabase with EfiSignatureLists containing any duplicated EfiSignatureData entries ( only the data contents are checked for effective equality signature owner is ignored )
"""
        Compute and return a tuple containing both a canonicalized database & a database of duplicates

        Returns -> (canonical: EfiSignatureDatabase, duplicates: EfiSignatureDatabase)
        canonical is an EfiSignatureDatabase where EfiSignatureLists are merged (where possible),
            deduplicated, & sorted, and the EfiSignatureData elements are also deduplicated & sorted
        duplicates is an EfiSignatureDatabase with EfiSignatureLists containing any duplicated
            EfiSignatureData entries (only the data contents are checked for effective equality,
            signature owner is ignored)
        """ # First group EFI_SIGNATURE_LISTS by type, merging them where possible # discard empty EfiSignatureLists # initialize it # initialize it # for each type, sort and de-duplicate, and then populate the respective databases # note the ordering of this section is the prescribed canonical order # first 1 EfiSignatureList for SHA256 hashes, EfiSignatureData elements sorted ascending # followed by EfiSignatureLists for each x509 certificate, sorted ascending by data content
self