Esempio n. 1
0
        /// <summary>
        /// Overridden to read the signature file.
        /// </summary>
        /// <param name="monitor">The monitor to use.</param>
        /// <returns>The signature or <see cref="SHA1Value.Zero"/> if it can't be read.</returns>
        protected override SHA1Value DoGetSignature(IActivityMonitor monitor)
        {
            var firstLine = SafeReadFirstLine(monitor, _signatureFile);

            if (firstLine != null && SHA1Value.TryParse(firstLine, out var signature))
            {
                return(signature);
            }
            return(SHA1Value.Zero);
        }
Esempio n. 2
0
        /// <summary>
        /// Tries to extract a SHA1 signature from an existing directory: the <see cref="SignatureFileName"/> is read if it exists.
        /// <para>
        /// This can be overridden to detect the signature differently.
        /// </para>
        /// </summary>
        /// <param name="monitor">The monitor to use.</param>
        /// <returns><see cref="SHA1Value.Zero"/> if not found.</returns>
        protected virtual SHA1Value DoGetSignature(IActivityMonitor monitor)
        {
            var f = Path.AppendPart(SignatureFileName);

            if (File.Exists(f) && SHA1Value.TryParse(File.ReadAllText(f), out var signature))
            {
                return(signature);
            }
            return(SHA1Value.Zero);
        }
Esempio n. 3
0
 /// <summary>
 /// Tries to extract a SHA1 signature from a file: the first valid SHA value that appears in the <see cref="NormalizedPath.Parts"/> (split by dot '.')
 /// form the end to start of the <see cref="Path"/>.
 /// <para>
 /// This can be overridden to detect the signature differently.
 /// </para>
 /// </summary>
 /// <param name="monitor">The monitor to use.</param>
 /// <returns><see cref="SHA1Value.Zero"/> if not found.</returns>
 protected virtual SHA1Value DoGetSignature(IActivityMonitor monitor)
 {
     foreach (var part in Path.Parts.Reverse())
     {
         foreach (var p in part.Split('.').Reverse())
         {
             if (SHA1Value.TryParse(p, out var signature))
             {
                 return(signature);
             }
         }
     }
     return(SHA1Value.Zero);
 }
        /// <summary>
        /// Overridden to match [assembly: CK.StObj.Signature( "..." )] SHA1 attribute in the first line.
        /// </summary>
        /// <param name="monitor"></param>
        /// <returns></returns>
        protected override SHA1Value DoGetSignature(IActivityMonitor monitor)
        {
            var firstLine = SafeReadFirstLine(monitor, Path);

            if (firstLine != null)
            {
                var m = Regex.Match(firstLine, @"\s*\[\s*assembly\s*:\s*CK.StObj.Signature\s*\(\s*@?""(?<1>.*?)""");
                if (m.Success && SHA1Value.TryParse(m.Groups[1].Value, out var signature))
                {
                    return(signature);
                }
            }
            monitor.Warn($"Unable to read [assembly: CK.StObj.Signature( \"...\" )] attribute from '{Path}'.");
            return(SHA1Value.Zero);
        }
Esempio n. 5
0
        public void SHA1_invalid_parse(int offset, string s, bool success)
        {
            SHA1Value v;

            SHA1Value.TryParse(s, offset, out v).Should().Be(success);
        }