You've already forked linux-packaging-mono
Imported Upstream version 6.8.0.73
Former-commit-id: d18deab1b47cfd3ad8cba82b3f37d00eec2170af
This commit is contained in:
parent
bceda29824
commit
73ee7591e8
@ -26,11 +26,33 @@ namespace Mono.Cecil {
|
||||
|
||||
static class CryptoService {
|
||||
|
||||
public static void StrongName (Stream stream, ImageWriter writer, StrongNameKeyPair key_pair)
|
||||
public static byte [] GetPublicKey (WriterParameters parameters)
|
||||
{
|
||||
using (var rsa = parameters.CreateRSA ()) {
|
||||
var cspBlob = CryptoConvert.ToCapiPublicKeyBlob (rsa);
|
||||
var publicKey = new byte [12 + cspBlob.Length];
|
||||
Buffer.BlockCopy (cspBlob, 0, publicKey, 12, cspBlob.Length);
|
||||
// The first 12 bytes are documented at:
|
||||
// http://msdn.microsoft.com/library/en-us/cprefadd/html/grfungethashfromfile.asp
|
||||
// ALG_ID - Signature
|
||||
publicKey [1] = 36;
|
||||
// ALG_ID - Hash
|
||||
publicKey [4] = 4;
|
||||
publicKey [5] = 128;
|
||||
// Length of Public Key (in bytes)
|
||||
publicKey [8] = (byte) (cspBlob.Length >> 0);
|
||||
publicKey [9] = (byte) (cspBlob.Length >> 8);
|
||||
publicKey [10] = (byte) (cspBlob.Length >> 16);
|
||||
publicKey [11] = (byte) (cspBlob.Length >> 24);
|
||||
return publicKey;
|
||||
}
|
||||
}
|
||||
|
||||
public static void StrongName (Stream stream, ImageWriter writer, WriterParameters parameters)
|
||||
{
|
||||
int strong_name_pointer;
|
||||
|
||||
var strong_name = CreateStrongName (key_pair, HashStream (stream, writer, out strong_name_pointer));
|
||||
var strong_name = CreateStrongName (parameters, HashStream (stream, writer, out strong_name_pointer));
|
||||
PatchStrongName (stream, strong_name_pointer, strong_name);
|
||||
}
|
||||
|
||||
@ -40,11 +62,11 @@ namespace Mono.Cecil {
|
||||
stream.Write (strong_name, 0, strong_name.Length);
|
||||
}
|
||||
|
||||
static byte [] CreateStrongName (StrongNameKeyPair key_pair, byte [] hash)
|
||||
static byte [] CreateStrongName (WriterParameters parameters, byte [] hash)
|
||||
{
|
||||
const string hash_algo = "SHA1";
|
||||
|
||||
using (var rsa = key_pair.CreateRSA ()) {
|
||||
using (var rsa = parameters.CreateRSA ()) {
|
||||
var formatter = new RSAPKCS1SignatureFormatter (rsa);
|
||||
formatter.SetHashAlgorithm (hash_algo);
|
||||
|
||||
@ -74,7 +96,6 @@ namespace Mono.Cecil {
|
||||
var sha1 = new SHA1Managed ();
|
||||
var buffer = new byte [buffer_size];
|
||||
using (var crypto_stream = new CryptoStream (Stream.Null, sha1, CryptoStreamMode.Write)) {
|
||||
|
||||
stream.Seek (0, SeekOrigin.Begin);
|
||||
CopyStreamChunk (stream, crypto_stream, buffer, header_size);
|
||||
|
||||
@ -125,7 +146,7 @@ namespace Mono.Cecil {
|
||||
|
||||
using (var crypto_stream = new CryptoStream (Stream.Null, sha1, CryptoStreamMode.Write)) {
|
||||
for (int i = 0; i < buffers.Length; i++) {
|
||||
crypto_stream.Write (buffers [0].buffer, 0, buffers [0].length);
|
||||
crypto_stream.Write (buffers [i].buffer, 0, buffers [i].length);
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,12 +169,17 @@ namespace Mono.Cecil {
|
||||
|
||||
static partial class Mixin {
|
||||
|
||||
public static RSA CreateRSA (this StrongNameKeyPair key_pair)
|
||||
public static RSA CreateRSA (this WriterParameters writer_parameters)
|
||||
{
|
||||
byte [] key;
|
||||
string key_container;
|
||||
|
||||
if (!TryGetKeyContainer (key_pair, out key, out key_container))
|
||||
if (writer_parameters.StrongNameKeyBlob != null)
|
||||
return CryptoConvert.FromCapiKeyBlob (writer_parameters.StrongNameKeyBlob);
|
||||
|
||||
if (writer_parameters.StrongNameKeyContainer != null)
|
||||
key_container = writer_parameters.StrongNameKeyContainer;
|
||||
else if (!TryGetKeyContainer (writer_parameters.StrongNameKeyPair, out key, out key_container))
|
||||
return CryptoConvert.FromCapiKeyBlob (key);
|
||||
|
||||
var parameters = new CspParameters {
|
||||
|
Reference in New Issue
Block a user