Пример #1
0
        /// <summary>
        /// Get only the files in the JAR that have no connection to the signing process
        /// </summary>
        /// <param name="this"></param>
        /// <returns>set of files which are not metadata/signing related</returns>
        public static IEnumerable <string> NonSignatureFiles(this IJar @this)
        {
            string[] manifestExtensions = new string[]
            {
                ".RSA",
                ".DSA",
                ".MF",
                ".SF"
            };

            return(@this.Files()
                   .Where(f =>
            {
                if (f.ToForwardSlashes().StartsWith(@"META-INF/"))
                {
                    // Is it a manifest or signature?
                    if (manifestExtensions.Any(ext =>
                                               ext.Equals(Path.GetExtension(f), StringComparison.InvariantCultureIgnoreCase)))
                    {
                        return false;
                    }

                    return true;
                }
                else
                {
                    // Not metadata
                    return true;
                }
            }));
        }
Пример #2
0
        public List <Signature> Find(IJar jar)
        {
            if (jar == null)
            {
                throw new ArgumentNullException(nameof(jar));
            }

            // Signature from base name -> data
            Dictionary <string, Signature> found = new Dictionary <string, Signature>(StringComparer.InvariantCultureIgnoreCase);

            foreach (string candidate in jar.Files())
            {
                string[] pathParts = candidate.Split('/');

                // Must be in META-INF
                if (pathParts.Length == 2 && pathParts[0] == "META-INF")
                {
                    string filenameOnly = pathParts[1];

                    if (filenameOnly.Equals("MANIFEST.MF", StringComparison.InvariantCultureIgnoreCase))
                    {
                        // We don't care about the non-signature manifest
                        continue;
                    }

                    // Base name being the actual overall signature name
                    string baseName = Path.GetFileNameWithoutExtension(filenameOnly);

                    Populate(found.AddOrGet(baseName, () => new Signature
                    {
                        BaseName = baseName
                    }),
                             candidate, filenameOnly);
                }
            }

            return(found.Values
                   .Where(s => !string.IsNullOrEmpty(s.ManifestPath) || s.Block != null)
                   .ToList());
        }