本文整理汇总了C#中ImmutableArray.DangerousGetUnderlyingArray方法的典型用法代码示例。如果您正苦于以下问题:C# ImmutableArray.DangerousGetUnderlyingArray方法的具体用法?C# ImmutableArray.DangerousGetUnderlyingArray怎么用?C# ImmutableArray.DangerousGetUnderlyingArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImmutableArray
的用法示例。
在下文中一共展示了ImmutableArray.DangerousGetUnderlyingArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PinnedMetadata
public unsafe PinnedMetadata(ImmutableArray<byte> metadata)
{
_bytes = GCHandle.Alloc(metadata.DangerousGetUnderlyingArray(), GCHandleType.Pinned);
this.Pointer = _bytes.AddrOfPinnedObject();
this.Size = metadata.Length;
this.Reader = new MetadataReader((byte*)this.Pointer, this.Size, MetadataReaderOptions.None, null);
}
示例2: TryGetPublicKey
/// <summary>
/// Try to retrieve the public key from a crypto blob.
/// </summary>
/// <remarks>
/// Can be either a PUBLICKEYBLOB or PRIVATEKEYBLOB. The BLOB must /// be unencrypted.
/// </remarks>
public unsafe static bool TryGetPublicKey(ImmutableArray<byte> blob, out ImmutableArray<byte> publicKey)
{
publicKey = ImmutableArray<byte>.Empty;
// Is this already a strong name PublicKeyBlob?
if (IsValidPublicKey(blob))
{
publicKey = blob;
return true;
}
// Must be at least as large as header + RSA info
if (blob.Length < sizeof(BlobHeader) + sizeof(RsaPubKey))
{
return false;
}
fixed (byte* backing = blob.DangerousGetUnderlyingArray())
{
var header = (BlobHeader*)backing;
var rsa = (RsaPubKey*)(backing + sizeof(BlobHeader));
// The RSA magic key must match the blob id
if (header->Type == PrivateKeyBlobId &&
rsa->Magic == RSA2)
{
return TryGetPublicKeyFromPrivateKeyBlob(backing, blob.Length, out publicKey);
}
else if (header->Type == PublicKeyBlobId &&
rsa->Magic == RSA1)
{
return TryGetPublicKeyFromPublicKeyBlob(backing, blob.Length, out publicKey);
}
}
return false;
}
示例3: IsValidPublicKeyUnsafe
private static unsafe bool IsValidPublicKeyUnsafe(ImmutableArray<byte> blob)
{
var blobArray = blob.DangerousGetUnderlyingArray();
fixed (byte* blobPtr = blobArray)
{
var pkb = (SnPublicKeyBlob*)blobPtr;
// The number of public key bytes must be the same as the size of the header plus the size of the public key data.
if (blob.Length != s_publicKeyHeaderSize + pkb->PublicKeySize)
{
return false;
}
// Check for the ECMA key, which does not obey the invariants checked below.
if (ByteSequenceComparer.Equals(blob, s_ecmaKey))
{
return true;
}
// The public key must be in the wincrypto PUBLICKEYBLOB format
if (pkb->PublicKey[0] != PublicKeyBlobId)
{
return false;
}
var signatureAlgorithmId = new AlgorithmId(pkb->SigAlgId);
if (signatureAlgorithmId.IsSet && signatureAlgorithmId.Class != AlgorithmClass.Signature)
{
return false;
}
var hashAlgorithmId = new AlgorithmId(pkb->HashAlgId);
if (hashAlgorithmId.IsSet && (hashAlgorithmId.Class != AlgorithmClass.Hash || hashAlgorithmId.SubId < AlgorithmSubId.Sha1Hash))
{
return false;
}
}
return true;
}
示例4: PinnedBlob
public PinnedBlob(ImmutableArray<byte> blob)
: this(blob.DangerousGetUnderlyingArray())
{
}