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

Remove incompatible API from PKCS netstandard2.0 lib #112591

Merged
merged 2 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,205 +5,120 @@
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.CmsSigner.#ctor(System.Security.Cryptography.Pkcs.SubjectIdentifierType,System.Security.Cryptography.X509Certificates.X509Certificate2,System.Security.Cryptography.AsymmetricAlgorithm)</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.CmsSigner.#ctor(System.Security.Cryptography.Pkcs.SubjectIdentifierType,System.Security.Cryptography.X509Certificates.X509Certificate2,System.Security.Cryptography.RSA,System.Security.Cryptography.RSASignaturePadding)</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.CmsSigner.get_PrivateKey</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.CmsSigner.get_SignaturePadding</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.CmsSigner.set_PrivateKey(System.Security.Cryptography.AsymmetricAlgorithm)</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.CmsSigner.set_SignaturePadding(System.Security.Cryptography.RSASignaturePadding)</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.ContentInfo.GetContentType(System.ReadOnlySpan{System.Byte})</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.EnvelopedCms.Decode(System.ReadOnlySpan{System.Byte})</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.EnvelopedCms.Decrypt(System.Security.Cryptography.Pkcs.RecipientInfo,System.Security.Cryptography.AsymmetricAlgorithm)</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SignedCms.AddCertificate(System.Security.Cryptography.X509Certificates.X509Certificate2)</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SignedCms.Decode(System.ReadOnlySpan{System.Byte})</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SignedCms.RemoveCertificate(System.Security.Cryptography.X509Certificates.X509Certificate2)</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SignerInfo.AddUnsignedAttribute(System.Security.Cryptography.AsnEncodedData)</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SignerInfo.get_SignatureAlgorithm</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SignerInfo.GetSignature</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SignerInfo.RemoveUnsignedAttribute(System.Security.Cryptography.AsnEncodedData)</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SubjectIdentifier.MatchesCertificate(System.Security.Cryptography.X509Certificates.X509Certificate2)</Target>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/net462/System.Security.Cryptography.Pkcs.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.CmsSigner.#ctor(System.Security.Cryptography.Pkcs.SubjectIdentifierType,System.Security.Cryptography.X509Certificates.X509Certificate2,System.Security.Cryptography.AsymmetricAlgorithm)</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.CmsSigner.#ctor(System.Security.Cryptography.Pkcs.SubjectIdentifierType,System.Security.Cryptography.X509Certificates.X509Certificate2,System.Security.Cryptography.RSA,System.Security.Cryptography.RSASignaturePadding)</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.CmsSigner.get_PrivateKey</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.CmsSigner.get_SignaturePadding</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.CmsSigner.set_PrivateKey(System.Security.Cryptography.AsymmetricAlgorithm)</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.CmsSigner.set_SignaturePadding(System.Security.Cryptography.RSASignaturePadding)</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.ContentInfo.GetContentType(System.ReadOnlySpan{System.Byte})</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.EnvelopedCms.Decode(System.ReadOnlySpan{System.Byte})</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.EnvelopedCms.Decrypt(System.Security.Cryptography.Pkcs.RecipientInfo,System.Security.Cryptography.AsymmetricAlgorithm)</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SignedCms.AddCertificate(System.Security.Cryptography.X509Certificates.X509Certificate2)</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SignedCms.Decode(System.ReadOnlySpan{System.Byte})</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SignedCms.RemoveCertificate(System.Security.Cryptography.X509Certificates.X509Certificate2)</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SignerInfo.AddUnsignedAttribute(System.Security.Cryptography.AsnEncodedData)</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SignerInfo.get_SignatureAlgorithm</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SignerInfo.GetSignature</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SignerInfo.RemoveUnsignedAttribute(System.Security.Cryptography.AsnEncodedData)</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Security.Cryptography.Pkcs.SubjectIdentifier.MatchesCertificate(System.Security.Cryptography.X509Certificates.X509Certificate2)</Target>
<Left>ref/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Left>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Left>
<Right>lib/netstandard2.0/System.Security.Cryptography.Pkcs.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0014</DiagnosticId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public sealed class CmsSigner
private RSASignaturePadding? _signaturePadding;

public X509Certificate2? Certificate { get; set; }
#if NET || NETSTANDARD2_1
public AsymmetricAlgorithm? PrivateKey { get; set; }
#else
private AsymmetricAlgorithm? PrivateKey { get; set; }
#endif
public X509Certificate2Collection Certificates { get; } = new X509Certificate2Collection();
public Oid DigestAlgorithm { get; set; }
public X509IncludeOption IncludeOption { get; set; }
Expand All @@ -32,7 +36,12 @@ public sealed class CmsSigner
/// Gets or sets the RSA signature padding to use.
/// </summary>
/// <value>The RSA signature padding to use.</value>
public RSASignaturePadding? SignaturePadding
#if NET || NETSTANDARD2_1
public
#else
private
#endif
RSASignaturePadding? SignaturePadding
{
get => _signaturePadding;
set
Expand Down Expand Up @@ -83,7 +92,12 @@ public CmsSigner(SubjectIdentifierType signerIdentifierType, X509Certificate2? c
{
}

public CmsSigner(SubjectIdentifierType signerIdentifierType, X509Certificate2? certificate, AsymmetricAlgorithm? privateKey)
#if NET || NETSTANDARD2_1
public
#else
private
#endif
CmsSigner(SubjectIdentifierType signerIdentifierType, X509Certificate2? certificate, AsymmetricAlgorithm? privateKey)
: this(signerIdentifierType, certificate, privateKey, signaturePadding: null)
{
}
Expand All @@ -105,7 +119,12 @@ public CmsSigner(SubjectIdentifierType signerIdentifierType, X509Certificate2? c
/// <param name="signaturePadding">
/// The RSA signature padding to use.
/// </param>
public CmsSigner(
#if NET || NETSTANDARD2_1
public
#else
internal
#endif
CmsSigner(
SubjectIdentifierType signerIdentifierType,
X509Certificate2? certificate,
RSA? privateKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public static Oid GetContentType(byte[] encodedMessage)
return PkcsPal.Instance.GetEncodedMessageType(encodedMessage);
}

#if NET || NETSTANDARD2_1
public static Oid GetContentType(ReadOnlySpan<byte> encodedMessage)
{
return PkcsPal.Instance.GetEncodedMessageType(encodedMessage);
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ public void Decode(byte[] encodedMessage)
/// <exception cref="CryptographicException">
/// The <paramref name="encodedMessage"/> parameter was not successfully decoded.
/// </exception>
public void Decode(ReadOnlySpan<byte> encodedMessage)
#if NET || NETSTANDARD2_1
public
#else
internal
#endif
void Decode(ReadOnlySpan<byte> encodedMessage)
{
if (_decryptorPal != null)
{
Expand Down Expand Up @@ -219,7 +224,12 @@ public void Decrypt(X509Certificate2Collection extraStore)
DecryptContent(RecipientInfos, extraStore);
}

public void Decrypt(RecipientInfo recipientInfo, AsymmetricAlgorithm? privateKey)
#if NET || NETSTANDARD2_1
public
#else
internal
#endif
void Decrypt(RecipientInfo recipientInfo, AsymmetricAlgorithm? privateKey)
{
if (recipientInfo is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public static Rfc3161TimestampRequest CreateFromSignerInfo(
// hash of the value of signature field within SignerInfo for the
// signedData being time-stamped.
return CreateFromData(
signerInfo.GetSignature(),
signerInfo.GetSignatureMemory().Span,
hashAlgorithm,
requestedPolicyId,
nonce,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ public void Decode(byte[] encodedMessage)
Decode(new ReadOnlySpan<byte>(encodedMessage));
}

public void Decode(ReadOnlySpan<byte> encodedMessage)
#if NET || NETSTANDARD2_1
public
#else
internal
#endif
void Decode(ReadOnlySpan<byte> encodedMessage)
{
// Hold a copy of the SignedData memory so we are protected against memory reuse by the caller.
_heldData = CopyContent(encodedMessage);
Expand Down Expand Up @@ -670,7 +675,12 @@ internal ref SignedDataAsn GetRawData()
return ref _signedData;
}

public void AddCertificate(X509Certificate2 certificate)
#if NET || NETSTANDARD2_1
public
#else
internal
#endif
void AddCertificate(X509Certificate2 certificate)
{
int existingLength = _signedData.CertificateSet?.Length ?? 0;

Expand Down Expand Up @@ -704,7 +714,12 @@ public void AddCertificate(X509Certificate2 certificate)
Reencode();
}

public void RemoveCertificate(X509Certificate2 certificate)
#if NET || NETSTANDARD2_1
public
#else
internal
#endif
void RemoveCertificate(X509Certificate2 certificate)
{
int existingLength = _signedData.CertificateSet?.Length ?? 0;

Expand Down
Loading
Loading