Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ReadOnlySpan in RIPEMD160 #3659

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Neo/Cryptography/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ public static byte[] RIPEMD160(this byte[] value)
/// <returns>The computed hash code.</returns>
public static byte[] RIPEMD160(this ReadOnlySpan<byte> value)
{
byte[] source = value.ToArray();
return source.RIPEMD160();
using var ripemd160 = new RIPEMD160Managed();

var output = new Span<byte>(new byte[ripemd160.HashSize]);
shargon marked this conversation as resolved.
Show resolved Hide resolved
if (!ripemd160.TryComputeHash(value, output, out _))
throw new Exception();
shargon marked this conversation as resolved.
Show resolved Hide resolved

return output.ToArray();
shargon marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/Neo/Cryptography/RIPEMD160Managed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography;

namespace Neo.Cryptography
{
Expand Down
Loading