static ImmutableArray <byte> CalculateChecksum(byte[] buffer, int offset, int count, SourceHashAlgorithm algorithmId) { using (HashAlgorithm algorithm = CryptographicHashProvider.TryGetAlgorithm(algorithmId)) { return(ImmutableArray.Create(algorithm.ComputeHash(buffer, offset, count))); } }
static ImmutableArray <byte> CalculateChecksum(Stream stream, SourceHashAlgorithm algorithmId) { using (HashAlgorithm algorithm = CryptographicHashProvider.TryGetAlgorithm(algorithmId)) { if (stream.CanSeek) { stream.Seek(0L, SeekOrigin.Begin); } return(ImmutableArray.Create(algorithm.ComputeHash(stream))); } }
internal ResourceDescription( string resourceName, string?fileName, Func <Stream> dataProvider, bool isPublic, bool isEmbedded, bool checkArgs ) { if (checkArgs) { if (dataProvider == null) { throw new ArgumentNullException(nameof(dataProvider)); } if (resourceName == null) { throw new ArgumentNullException(nameof(resourceName)); } if (!MetadataHelpers.IsValidMetadataIdentifier(resourceName)) { throw new ArgumentException( CodeAnalysisResources.EmptyOrInvalidResourceName, nameof(resourceName) ); } if (!isEmbedded) { if (fileName == null) { throw new ArgumentNullException(nameof(fileName)); } if (!MetadataHelpers.IsValidMetadataFileName(fileName)) { throw new ArgumentException( CodeAnalysisResources.EmptyOrInvalidFileName, nameof(fileName) ); } } } this.ResourceName = resourceName; this.DataProvider = dataProvider; this.FileName = isEmbedded ? null : fileName; this.IsPublic = isPublic; _hashes = new ResourceHashProvider(this); }
// internal for testing internal static ImmutableArray <byte> CalculatePublicKeyToken(ImmutableArray <byte> publicKey) { var hash = CryptographicHashProvider.ComputeSha1(publicKey); // SHA1 hash is always 160 bits: Debug.Assert(hash.Length == CryptographicHashProvider.Sha1HashSize); // PublicKeyToken is the low 64 bits of the SHA-1 hash of the public key. int l = hash.Length - 1; var result = ArrayBuilder <byte> .GetInstance(PublicKeyTokenSize); for (int i = 0; i < PublicKeyTokenSize; i++) { result.Add(hash[l - i]); } return(result.ToImmutableAndFree()); }
internal ResourceDescription(string resourceName, string fileName, Func <Stream> dataProvider, bool isPublic, bool isEmbedded, bool checkArgs) { if (checkArgs) { if (dataProvider == null) { throw new ArgumentNullException("dataProvider"); } if (resourceName == null) { throw new ArgumentNullException("resourceName"); } if (resourceName.Length == 0 || resourceName.IndexOf('\0') >= 0) { throw new ArgumentException(CodeAnalysisResources.EmptyOrInvalidResourceName, "resourceName"); } if (!isEmbedded) { if (fileName == null) { throw new ArgumentNullException("fileName"); } if (fileName.Length == 0 || !PathUtilities.IsValidFileName(fileName)) { throw new ArgumentException(CodeAnalysisResources.EmptyOrInvalidFileName, "fileName"); } } } this.ResourceName = resourceName; this.DataProvider = dataProvider; this.FileName = isEmbedded ? null : fileName; this.IsPublic = isPublic; this.hashes = new ResourceHashProvider(this); }
internal ResourceDescription(string resourceName, string fileName, Func<Stream> dataProvider, bool isPublic, bool isEmbedded, bool checkArgs) { if (checkArgs) { if (dataProvider == null) { throw new ArgumentNullException(nameof(dataProvider)); } if (resourceName == null) { throw new ArgumentNullException(nameof(resourceName)); } if (!MetadataHelpers.IsValidMetadataIdentifier(resourceName)) { throw new ArgumentException(CodeAnalysisResources.EmptyOrInvalidResourceName, nameof(resourceName)); } if (!isEmbedded) { if (fileName == null) { throw new ArgumentNullException(nameof(fileName)); } if (!MetadataHelpers.IsValidMetadataFileName(fileName)) { throw new ArgumentException(CodeAnalysisResources.EmptyOrInvalidFileName, nameof(fileName)); } } } this.ResourceName = resourceName; this.DataProvider = dataProvider; this.FileName = isEmbedded ? null : fileName; this.IsPublic = isPublic; _hashes = new ResourceHashProvider(this); }
internal ResourceDescription(string resourceName, string fileName, Func<Stream> dataProvider, bool isPublic, bool isEmbedded, bool checkArgs) { if (checkArgs) { if (dataProvider == null) { throw new ArgumentNullException("dataProvider"); } if (resourceName == null) { throw new ArgumentNullException("resourceName"); } if (resourceName.Length == 0 || resourceName.IndexOf('\0') >= 0) { throw new ArgumentException(CodeAnalysisResources.EmptyOrInvalidResourceName, "resourceName"); } if (!isEmbedded) { if (fileName == null) { throw new ArgumentNullException("fileName"); } if (fileName.Length == 0 || !PathUtilities.IsValidFileName(fileName)) { throw new ArgumentException(CodeAnalysisResources.EmptyOrInvalidFileName, "fileName"); } } } this.ResourceName = resourceName; this.DataProvider = dataProvider; this.FileName = isEmbedded ? null : fileName; this.IsPublic = isPublic; this.hashes = new ResourceHashProvider(this); }