Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
b812f5d5
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b812f5d5
编写于
12月 22, 2017
作者:
J
Jason Malinowski
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dotnet/dev15.6-preview2' into merges/dev15.6-preview2-to-master-20171222-080016
上级
fa6ee581
d3d24154
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
10 deletion
+23
-10
src/Workspaces/Core/Portable/Workspace/Solution/Checksum.cs
src/Workspaces/Core/Portable/Workspace/Solution/Checksum.cs
+23
-10
未找到文件。
src/Workspaces/Core/Portable/Workspace/Solution/Checksum.cs
浏览文件 @
b812f5d5
...
...
@@ -14,6 +14,15 @@ namespace Microsoft.CodeAnalysis
/// </summary>
internal
sealed
partial
class
Checksum
:
IObjectWritable
,
IEquatable
<
Checksum
>
{
/// <summary>
/// The intended size of the <see cref="Sha1Hash"/> structure. Some runtime environments are known to deviate
/// from this size, so the implementation code should remain functionally correct even when the structure size
/// is greater than this value.
/// </summary>
/// <seealso href="https://bugzilla.xamarin.com/show_bug.cgi?id=60298">LayoutKind.Explicit, Size = 12 ignored with 64bit alignment</seealso>
/// <seealso href="https://github.com/dotnet/roslyn/issues/23722">Checksum throws on Mono 64-bit</seealso>
private
const
int
Sha1HashSize
=
20
;
public
static
readonly
Checksum
Null
=
new
Checksum
(
Array
.
Empty
<
byte
>());
private
Sha1Hash
_checkSum
;
...
...
@@ -25,14 +34,15 @@ public unsafe Checksum(byte[] checksum)
_checkSum
=
default
;
return
;
}
else
if
(
checksum
.
Length
!=
sizeof
(
Sha1Hash
)
)
else
if
(
checksum
.
Length
!=
Sha1HashSize
)
{
throw
new
ArgumentException
(
$"
{
nameof
(
checksum
)}
must be a SHA-1 hash"
,
nameof
(
checksum
));
}
fixed
(
byte
*
data
=
checksum
)
{
_checkSum
=
*(
Sha1Hash
*)
data
;
// Avoid a direct dereferencing assignment since sizeof(Sha1Hash) may be greater than Sha1HashSize.
_checkSum
=
Sha1Hash
.
FromPointer
((
Sha1Hash
*)
data
);
}
}
...
...
@@ -65,7 +75,7 @@ public override unsafe string ToString()
*(
Sha1Hash
*)
dataPtr
=
_checkSum
;
}
return
Convert
.
ToBase64String
(
data
);
return
Convert
.
ToBase64String
(
data
,
0
,
Sha1HashSize
);
}
public
static
bool
operator
==(
Checksum
left
,
Checksum
right
)
...
...
@@ -98,13 +108,7 @@ public static string GetChecksumsLogInfo(IEnumerable<Checksum> checksums)
/// This structure stores the 20-byte SHA 1 hash as an inline value rather than requiring the use of
/// <c>byte[]</c>.
/// </summary>
/// <remarks>
/// Pack = 4 is specified to work around a Mono runtime behavior where on 64-bit the size of the
/// struct would be 24 and not 20 due to alignment (it ignores Size = 20, but Pack = 4 does it).
/// Without this fix the ctor would throw because it would use sizeof(Sha1Hash) == 24.
/// This bug is tracked by https://bugzilla.xamarin.com/show_bug.cgi?id=60298.
/// </remarks>
[
StructLayout
(
LayoutKind
.
Explicit
,
Size
=
20
,
Pack
=
4
)]
[
StructLayout
(
LayoutKind
.
Explicit
,
Size
=
Sha1HashSize
)]
private
struct
Sha1Hash
:
IEquatable
<
Sha1Hash
>
{
[
FieldOffset
(
0
)]
...
...
@@ -129,6 +133,15 @@ public void WriteTo(ObjectWriter writer)
writer
.
WriteInt32
(
Data3
);
}
public
static
unsafe
Sha1Hash
FromPointer
(
Sha1Hash
*
hash
)
{
Sha1Hash
result
=
default
;
result
.
Data1
=
hash
->
Data1
;
result
.
Data2
=
hash
->
Data2
;
result
.
Data3
=
hash
->
Data3
;
return
result
;
}
public
static
Sha1Hash
ReadFrom
(
ObjectReader
reader
)
{
Sha1Hash
result
=
default
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录