388 references to SourceHashAlgorithm
Microsoft.CodeAnalysis (87)
EncodedStringText.cs (8)
54/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
74SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1,
87SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1,
130SourceHashAlgorithm checksumAlgorithm,
230internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
233internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
Text\LargeText.cs (4)
33internal LargeText(ImmutableArray<char[]> chunks, Encoding? encodingOpt, ImmutableArray<byte> checksum, SourceHashAlgorithm checksumAlgorithm, ImmutableArray<byte> embeddedTextBlob)
50internal LargeText(ImmutableArray<char[]> chunks, Encoding? encodingOpt, SourceHashAlgorithm checksumAlgorithm)
55internal static SourceText Decode(Stream stream, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
81internal static SourceText Decode(TextReader reader, int length, Encoding? encodingOpt, SourceHashAlgorithm checksumAlgorithm)
Text\SourceText.cs (20)
36private readonly SourceHashAlgorithm _checksumAlgorithm;
50protected SourceText(ImmutableArray<byte> checksum = default, SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1, SourceTextContainer? container = null)
64internal SourceText(ImmutableArray<byte> checksum, SourceHashAlgorithm checksumAlgorithm, ImmutableArray<byte> embeddedTextBlob)
82internal static void ValidateChecksumAlgorithm(SourceHashAlgorithm checksumAlgorithm)
105public static SourceText From(string text, Encoding? encoding = null, SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1)
135SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1)
154public static SourceText From(Stream stream, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected)
183SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1,
225public static SourceText From(byte[] buffer, int length, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected)
253SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1,
384public SourceHashAlgorithm ChecksumAlgorithm => _checksumAlgorithm;
424/// If this text was constructed via <see cref="From(byte[], int, Encoding, SourceHashAlgorithm, bool, bool)"/> or
425/// <see cref="From(Stream, Encoding, SourceHashAlgorithm, bool, bool)"/>, then the canBeEmbedded arg must have
683internal static ImmutableArray<byte> CalculateChecksum(byte[] buffer, int offset, int count, SourceHashAlgorithm algorithmId)
692internal static ImmutableArray<byte> CalculateChecksum(Stream stream, SourceHashAlgorithm algorithmId)
Microsoft.CodeAnalysis.CodeStyle (8)
src\Compilers\Core\Portable\EncodedStringText.cs (8)
54/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
74SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1,
87SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1,
130SourceHashAlgorithm checksumAlgorithm,
230internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
233internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
Microsoft.CodeAnalysis.CSharp (14)
Syntax\CSharpSyntaxTree.cs (5)
348checksumAlgorithm: SourceHashAlgorithm.Sha1,
362SourceHashAlgorithm checksumAlgorithm)
402checksumAlgorithm: SourceHashAlgorithm.Sha1,
460return ParseText(SourceText.From(text, encoding, SourceHashAlgorithm.Sha1), options, path, diagnosticOptions, isGeneratedCode, cancellationToken);
928=> ParseText(SourceText.From(text, encoding, SourceHashAlgorithm.Sha1), options, path, diagnosticOptions, isGeneratedCode: null, cancellationToken);
Syntax\SyntaxFactory.cs (2)
1548=> CSharpSyntaxTree.Create((CSharpSyntaxNode)root, (CSharpParseOptions?)options ?? CSharpParseOptions.Default, path, encoding, SourceHashAlgorithm.Sha1);
1562return CSharpSyntaxTree.ParseText(SourceText.From(text, encoding, SourceHashAlgorithm.Sha1), (CSharpParseOptions?)options, path, diagnosticOptions: null, isGeneratedCode: null, cancellationToken);
Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests (4)
Microsoft.CodeAnalysis.CSharp.EditorFeatures.UnitTests (1)
Microsoft.CodeAnalysis.CSharp.Emit2.UnitTests (4)
Microsoft.CodeAnalysis.CSharp.Syntax.UnitTests (9)
Syntax\SyntaxTreeTests.cs (6)
86SyntaxTreeFactoryKind.ParseText => CSharpSyntaxTree.ParseText(SourceText.From(source, Encoding.UTF8, SourceHashAlgorithm.Sha256), parseOptions),
87SyntaxTreeFactoryKind.Subclass => new MockCSharpSyntaxTree(root, SourceText.From(source, Encoding.UTF8, SourceHashAlgorithm.Sha256), parseOptions),
122Assert.Equal(SourceHashAlgorithm.Sha1, tree.GetText().ChecksumAlgorithm);
134Assert.Equal(SourceHashAlgorithm.Sha1, tree.GetText().ChecksumAlgorithm);
253Assert.Equal(SourceHashAlgorithm.Sha1, newText.ChecksumAlgorithm);
295Assert.Equal(SourceHashAlgorithm.Sha1, newText.ChecksumAlgorithm);
Microsoft.CodeAnalysis.CSharp.Test.Utilities (3)
Microsoft.CodeAnalysis.CSharp.Workspaces (3)
Microsoft.CodeAnalysis.EditorFeatures (4)
Microsoft.CodeAnalysis.EditorFeatures.Text (4)
Extensions.SnapshotSourceText.cs (3)
38private SnapshotSourceText(ITextBufferCloneService? textBufferCloneService, ITextSnapshot editorSnapshot, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, TextBufferContainer container)
49public SnapshotSourceText(ITextBufferCloneService? textBufferCloneService, ITextImage textImage, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, TextBufferContainer? container)
267public ClosedSnapshotSourceText(ITextBufferCloneService? textBufferCloneService, ITextImage textImage, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm)
Microsoft.CodeAnalysis.EditorFeatures.UnitTests (1)
Microsoft.CodeAnalysis.Features (21)
EditAndContinue\CommittedSolution.cs (8)
313var maybePdbHasDocument = TryReadSourceFileChecksumFromPdb(document, out var requiredChecksum, out var checksumAlgorithm);
322SourceText sourceText, string filePath, Document? currentDocument, IPdbMatchingSourceTextProvider sourceTextProvider, ImmutableArray<byte> requiredChecksum, SourceHashAlgorithm checksumAlgorithm, CancellationToken cancellationToken)
389if (TryReadSourceFileChecksumFromPdb(debugInfoReader, sourceFilePath, out var requiredChecksum, out var checksumAlgorithm) == true &&
436private static bool IsMatchingSourceText(SourceText sourceText, ImmutableArray<byte> requiredChecksum, SourceHashAlgorithm checksumAlgorithm)
439private static Optional<SourceText?> TryGetPdbMatchingSourceTextFromDisk(string sourceFilePath, Encoding? encoding, ImmutableArray<byte> requiredChecksum, SourceHashAlgorithm checksumAlgorithm)
470private bool? TryReadSourceFileChecksumFromPdb(Document document, out ImmutableArray<byte> requiredChecksum, out SourceHashAlgorithm checksumAlgorithm)
494private static bool? TryReadSourceFileChecksumFromPdb(EditAndContinueMethodDebugInfoReader debugInfoReader, string sourceFilePath, out ImmutableArray<byte> checksum, out SourceHashAlgorithm algorithm)
508if (algorithm == SourceHashAlgorithm.None)
PdbSourceDocument\PdbSourceDocumentMetadataAsSourceFileProvider.cs (4)
224var projectChecksumAlgorithm = sourceDocuments[0].ChecksumAlgorithm;
307private ProjectInfo? CreateProjectInfo(Workspace workspace, Project project, ImmutableDictionary<string, string> pdbCompilationOptions, string assemblyName, string assemblyVersion, SourceHashAlgorithm checksumAlgorithm)
489internal sealed record SourceDocument(string FilePath, SourceHashAlgorithm ChecksumAlgorithm, ImmutableArray<byte> Checksum, byte[]? EmbeddedTextBytes, string? SourceLinkUrl);
491internal record struct SourceDocumentInfo(DocumentId DocumentId, Encoding Encoding, SourceHashAlgorithm ChecksumAlgorithm, ProjectId SourceProjectId, Workspace SourceWorkspace, DocumentInfo DocumentInfo);
Microsoft.CodeAnalysis.Features.Test.Utilities (5)
Microsoft.CodeAnalysis.Features.UnitTests (13)
EditAndContinue\EditAndContinueWorkspaceServiceTests.cs (11)
70var sourceTreeC1 = SyntaxFactory.ParseSyntaxTree(SourceText.From(sourceBytesC1, sourceBytesC1.Length, encodingC, SourceHashAlgorithm.Sha1), TestOptions.Regular, sourceFileC.Path);
84.WithProjectChecksumAlgorithm(projectPId, SourceHashAlgorithm.Sha1);
115Assert.Equal(SourceHashAlgorithm.Sha1, solution.GetDocument(documentIdA).GetTextSynchronously(default).ChecksumAlgorithm);
116Assert.Equal(SourceHashAlgorithm.Sha1, solution.GetDocument(documentIdB).GetTextSynchronously(default).ChecksumAlgorithm);
117Assert.Equal(SourceHashAlgorithm.Sha1, solution.GetDocument(documentIdC).GetTextSynchronously(default).ChecksumAlgorithm);
118Assert.Equal(SourceHashAlgorithm.Sha1, solution.GetDocument(documentIdE).GetTextSynchronously(default).ChecksumAlgorithm);
623AddDocument("a.cs", SourceText.From(source1, Encoding.UTF8, SourceHashAlgorithm.Sha1), filePath: sourceFile.Path);
921WithProjectChecksumAlgorithm(projectId, SourceHashAlgorithm.Sha1).
923AddDocument(documentId, "test.cs", SourceText.From(source1, encoding, SourceHashAlgorithm.Sha1), filePath: sourceFile.Path);
926var moduleId = EmitAndLoadLibraryToDebuggee(source1, sourceFilePath: sourceFile.Path, encoding: encoding, checksumAlgorithm: SourceHashAlgorithm.Sha256);
1791context.AddSource("generated.cs", SourceText.From("generated: " + additionalText, Encoding.UTF8, SourceHashAlgorithm.Sha256));
Microsoft.CodeAnalysis.LanguageServer (3)
Microsoft.CodeAnalysis.Rebuild (5)
Microsoft.CodeAnalysis.Rebuild.UnitTests (12)
Microsoft.CodeAnalysis.Remote.ServiceHub (1)
Microsoft.CodeAnalysis.Remote.Workspaces (1)
Microsoft.CodeAnalysis.Test.Utilities (2)
Microsoft.CodeAnalysis.UnitTests (48)
EmbeddedTextTests.cs (26)
28Assert.Throws<ArgumentException>("checksumAlgorithm", () => EmbeddedText.FromBytes("path", new ArraySegment<byte>(new byte[0], 0, 0), SourceHashAlgorithm.None));
54Assert.Throws<ArgumentException>("checksumAlgorithm", () => EmbeddedText.FromStream("path", new MemoryStream(), SourceHashAlgorithm.None));
81var text = EmbeddedText.FromBytes("pathToEmpty", new ArraySegment<byte>(new byte[0], 0, 0), SourceHashAlgorithm.Sha1);
83Assert.Equal(SourceHashAlgorithm.Sha1, text.ChecksumAlgorithm);
84AssertEx.Equal(SourceText.CalculateChecksum(new byte[0], 0, 0, SourceHashAlgorithm.Sha1), text.Checksum);
91var text = EmbeddedText.FromStream("pathToEmpty", new MemoryStream(new byte[0]), SourceHashAlgorithm.Sha1);
92var checksum = SourceText.CalculateChecksum(new byte[0], 0, 0, SourceHashAlgorithm.Sha1);
95Assert.Equal(SourceHashAlgorithm.Sha1, text.ChecksumAlgorithm);
103var source = SourceText.From("", new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), SourceHashAlgorithm.Sha1);
105var checksum = SourceText.CalculateChecksum(new byte[0], 0, 0, SourceHashAlgorithm.Sha1);
108Assert.Equal(SourceHashAlgorithm.Sha1, text.ChecksumAlgorithm);
117var checksum = SourceText.CalculateChecksum(bytes, 0, bytes.Length, SourceHashAlgorithm.Sha1);
121Assert.Equal(SourceHashAlgorithm.Sha1, text.ChecksumAlgorithm);
132var checksum = SourceText.CalculateChecksum(bytes, 0, bytes.Length, SourceHashAlgorithm.Sha1);
137Assert.Equal(SourceHashAlgorithm.Sha1, text.ChecksumAlgorithm);
145var source = SourceText.From(SmallSource, Encoding.UTF8, SourceHashAlgorithm.Sha1);
149Assert.Equal(SourceHashAlgorithm.Sha1, text.ChecksumAlgorithm);
200var expected = SourceText.From(SmallSource, Encoding.UTF8, SourceHashAlgorithm.Sha1);
203var actual = SourceText.From(new StringReader(SmallSource), SmallSource.Length, Encoding.UTF8, SourceHashAlgorithm.Sha1);
215var expected = SourceText.From(LargeSource, Encoding.UTF8, SourceHashAlgorithm.Sha1);
218var actual = SourceText.From(new StringReader(LargeSource), LargeSource.Length, Encoding.UTF8, SourceHashAlgorithm.Sha1);
236SourceText.From(new MemoryStream(bytes), Encoding.ASCII, SourceHashAlgorithm.Sha1, canBeEmbedded: true) :
237SourceText.From(bytes, bytes.Length, Encoding.ASCII, SourceHashAlgorithm.Sha1, canBeEmbedded: true);
241Assert.Equal(SourceHashAlgorithm.Sha1, text.ChecksumAlgorithm);
242AssertEx.Equal(SourceText.CalculateChecksum(bytes, 0, bytes.Length, SourceHashAlgorithm.Sha1), source.GetChecksum());
256Assert.Equal(SourceHashAlgorithm.Sha1, text.ChecksumAlgorithm);
Text\StringTextDecodingTests.cs (8)
19private static SourceText CreateMemoryStreamBasedEncodedText(string text, Encoding writeEncoding, Encoding readEncodingOpt, SourceHashAlgorithm algorithm = SourceHashAlgorithm.Sha1)
26private static SourceText CreateMemoryStreamBasedEncodedText(byte[] bytes, Encoding readEncodingOpt, SourceHashAlgorithm algorithm = SourceHashAlgorithm.Sha1)
42SourceHashAlgorithm algorithm = SourceHashAlgorithm.Sha1)
134var data = CreateMemoryStreamBasedEncodedText("", Encoding.UTF8, readEncodingOpt: null, algorithm: SourceHashAlgorithm.Sha256);
161EncodedStringText.TestAccessor.Decode(stream, utf8, SourceHashAlgorithm.Sha1, throwIfBinaryDetected: false, canBeEmbedded: false);
Microsoft.CodeAnalysis.VisualBasic (10)
Syntax\SyntaxNodeFactories.vb (2)
37Return VisualBasicSyntaxTree.Create(DirectCast(root, VisualBasicSyntaxNode), If(DirectCast(options, VisualBasicParseOptions), VisualBasicParseOptions.Default), path, encoding, SourceHashAlgorithm.Sha1)
50Return ParseSyntaxTree(SourceText.From(text, encoding, SourceHashAlgorithm.Sha1), options, path, cancellationToken)
Microsoft.CodeAnalysis.VisualBasic.CommandLine.UnitTests (3)
Microsoft.CodeAnalysis.VisualBasic.Syntax.UnitTests (5)
Microsoft.CodeAnalysis.VisualBasic.Test.Utilities (1)
Microsoft.CodeAnalysis.VisualBasic.Workspaces (3)
Microsoft.CodeAnalysis.Workspaces (59)
src\Compilers\Core\Portable\EncodedStringText.cs (8)
54/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
74SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1,
87SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1,
130SourceHashAlgorithm checksumAlgorithm,
230internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
233internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests (3)
Microsoft.CodeAnalysis.Workspaces.Test.Utilities (2)
Microsoft.CodeAnalysis.Workspaces.UnitTests (39)
SolutionTests\SolutionTests.cs (38)
305Assert.Equal(SourceHashAlgorithm.Sha1, tree.GetText().ChecksumAlgorithm);
350var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
451var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
539var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
622var text = SourceText.From("new text without pp directives", encoding: null, SourceHashAlgorithm.Sha1);
705var text = SourceText.From("#if true", encoding: null, SourceHashAlgorithm.Sha1);
781var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
868var text = SourceText.From(" ", encoding: null, SourceHashAlgorithm.Sha1);
1108loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class NewD1;", Encoding.UTF32, SourceHashAlgorithm.Sha256), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD1.cs"))),
1127loader: TextLoader.From(TextAndVersion.Create(SourceText.From("new text1", Encoding.UTF32, SourceHashAlgorithm.Sha256), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD1.cs"))),
1146loader: TextLoader.From(TextAndVersion.Create(SourceText.From("#new empty1", Encoding.UTF32, SourceHashAlgorithm.Sha256), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD1.cs"))),
1238Assert.Equal(SourceHashAlgorithm.Sha256, newText1.ChecksumAlgorithm);
1259Assert.Equal(SourceHashAlgorithm.Sha256, newAddText1.ChecksumAlgorithm);
1280Assert.Equal(SourceHashAlgorithm.Sha256, newConfigText1.ChecksumAlgorithm);
1618var textLoaderA = new TestTextLoader("class A {}", SourceHashAlgorithm.Sha1);
1619var textC = SourceText.From("class C {}", encoding: null, checksumAlgorithm: SourceHashAlgorithm.Sha1);
1623.WithProjectChecksumAlgorithm(projectId, SourceHashAlgorithm.Sha1);
1630await Verify(solution.GetRequiredDocument(documentAId), SourceHashAlgorithm.Sha1);
1631await Verify(solution.GetRequiredDocument(documentBId), SourceHashAlgorithm.Sha1);
1632await Verify(solution.GetRequiredDocument(documentCId), SourceHashAlgorithm.Sha1);
1633await Verify(solution.GetRequiredDocument(fileDocumentId), SourceHashAlgorithm.Sha1, checksumSHA1);
1636solution = solution.WithProjectChecksumAlgorithm(projectId, SourceHashAlgorithm.Sha256);
1637await Verify(solution.GetRequiredDocument(documentAId), SourceHashAlgorithm.Sha1);
1638await Verify(solution.GetRequiredDocument(documentBId), SourceHashAlgorithm.Sha1);
1639await Verify(solution.GetRequiredDocument(documentCId), SourceHashAlgorithm.Sha1);
1640await Verify(solution.GetRequiredDocument(fileDocumentId), SourceHashAlgorithm.Sha256, checksumSHA256);
1643solution = solution.WithProjectChecksumAlgorithm(projectId, SourceHashAlgorithm.Sha1);
1644await Verify(solution.GetRequiredDocument(documentAId), SourceHashAlgorithm.Sha1);
1645await Verify(solution.GetRequiredDocument(documentBId), SourceHashAlgorithm.Sha1);
1646await Verify(solution.GetRequiredDocument(documentCId), SourceHashAlgorithm.Sha1);
1647await Verify(solution.GetRequiredDocument(fileDocumentId), SourceHashAlgorithm.Sha1, checksumSHA1);
1649static async Task Verify(Document document, SourceHashAlgorithm expectedAlgorithm, byte[]? expectedChecksum = null)
2365var loader = new TestTextLoader(checksumAlgorithm: SourceHashAlgorithm.Sha1);
2373Assert.Equal(SourceHashAlgorithm.Sha1, document.GetTextSynchronously(default).ChecksumAlgorithm);
2483var root = CSharp.SyntaxFactory.ParseSyntaxTree(SourceText.From("class C {}", encoding: null, SourceHashAlgorithm.Sha1)).GetRoot();
2484Assert.Equal(SourceHashAlgorithm.Sha1, root.SyntaxTree.GetText().ChecksumAlgorithm);
2513Assert.Equal(SourceHashAlgorithm.Sha1, root.SyntaxTree.GetText().ChecksumAlgorithm);
3773.AddDocument(did, "test", SourceText.From(language == LanguageNames.CSharp ? "class C {}" : "Class C : End Class", Encoding.UTF8, SourceHashAlgorithm.Sha256), filePath: "old path");
Microsoft.VisualStudio.LanguageServices.CSharp.UnitTests (1)
Roslyn.VisualStudio.Next.UnitTests (8)
Services\ServiceHubServicesTests.cs (6)
496private static SourceText CreateText(string content, Encoding encoding = null, SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1)
506return SourceText.From(stream, encoding, SourceHashAlgorithm.Sha1, throwIfBinaryDetected: true);
510return SourceText.From(bytes, bytes.Length, encoding, SourceHashAlgorithm.Sha1, throwIfBinaryDetected: true);
593[("SG.cs", CreateText("X", Encoding.UTF8, checksumAlgorithm: SourceHashAlgorithm.Sha1))],
594[("SG.cs", CreateText("X", Encoding.UTF8, checksumAlgorithm: SourceHashAlgorithm.Sha256))]);
StackDepthTest (1)