use of com.android.apksig.internal.jar.ManifestParser in project apksig by venshine.
the class V1SchemeVerifier method parseManifest.
/**
* Parses raw representation of MANIFEST.MF file into a pair of main entry manifest section
* representation and a mapping between entry name and its manifest section representation.
*
* @param manifestBytes raw representation of Manifest.MF
* @param cdEntryNames expected set of entry names
* @param result object to keep track of errors that happened during the parsing
* @return a pair of main entry manifest section representation and a mapping between entry name
* and its manifest section representation
*/
public static Pair<ManifestParser.Section, Map<String, ManifestParser.Section>> parseManifest(byte[] manifestBytes, Set<String> cdEntryNames, Result result) {
ManifestParser manifest = new ManifestParser(manifestBytes);
ManifestParser.Section manifestMainSection = manifest.readSection();
List<ManifestParser.Section> manifestIndividualSections = manifest.readAllSections();
Map<String, ManifestParser.Section> entryNameToManifestSection = new HashMap<>(manifestIndividualSections.size());
int manifestSectionNumber = 0;
for (ManifestParser.Section manifestSection : manifestIndividualSections) {
manifestSectionNumber++;
String entryName = manifestSection.getName();
if (entryName == null) {
result.addError(Issue.JAR_SIG_UNNNAMED_MANIFEST_SECTION, manifestSectionNumber);
continue;
}
if (entryNameToManifestSection.put(entryName, manifestSection) != null) {
result.addError(Issue.JAR_SIG_DUPLICATE_MANIFEST_SECTION, entryName);
continue;
}
if (!cdEntryNames.contains(entryName)) {
result.addError(Issue.JAR_SIG_MISSING_ZIP_ENTRY_REFERENCED_IN_MANIFEST, entryName);
continue;
}
}
return Pair.of(manifestMainSection, entryNameToManifestSection);
}
Aggregations