mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-18 03:51:19 -10:00
* X509Store.cs: Removed old store code (as it has changed a lot in Mono.Security). svn path=/trunk/mcs/; revision=30854
193 lines
4.9 KiB
C#
Executable File
193 lines
4.9 KiB
C#
Executable File
//
|
|
// X509Store.cs - System.Security.Cryptography.X509Certificates.X509Store
|
|
//
|
|
// Author:
|
|
// Sebastien Pouliot <[email protected]>
|
|
//
|
|
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
|
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining
|
|
// a copy of this software and associated documentation files (the
|
|
// "Software"), to deal in the Software without restriction, including
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
|
// permit persons to whom the Software is furnished to do so, subject to
|
|
// the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be
|
|
// included in all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
//
|
|
|
|
#if NET_2_0
|
|
|
|
using System;
|
|
|
|
using Mono.Security.X509;
|
|
|
|
namespace System.Security.Cryptography.X509Certificates {
|
|
|
|
public sealed class X509Store {
|
|
|
|
private string _name;
|
|
private StoreLocation _location;
|
|
private X509CertificateExCollection _certs;
|
|
private OpenFlags _flags;
|
|
|
|
// constructors
|
|
|
|
// BUG: MY when using this constructor - My when using StoreName.My
|
|
public X509Store ()
|
|
: this ("MY", StoreLocation.CurrentUser)
|
|
{
|
|
}
|
|
|
|
public X509Store (string storeName)
|
|
: this (storeName, StoreLocation.CurrentUser)
|
|
{
|
|
}
|
|
|
|
public X509Store (StoreName storeName)
|
|
: this (StoreNameToString (storeName), StoreLocation.CurrentUser)
|
|
{
|
|
}
|
|
|
|
public X509Store (StoreLocation storeLocation)
|
|
: this ("MY", storeLocation)
|
|
{
|
|
}
|
|
|
|
public X509Store (StoreName storeName, StoreLocation storeLocation)
|
|
: this (StoreNameToString (storeName), StoreLocation.CurrentUser)
|
|
{
|
|
}
|
|
|
|
[MonoTODO ("call Mono.Security.X509.X509Store*")]
|
|
public X509Store (string storeName, StoreLocation storeLocation)
|
|
{
|
|
if (storeName == null)
|
|
throw new ArgumentNullException ("storeName");
|
|
|
|
_name = storeName;
|
|
_location = storeLocation;
|
|
}
|
|
|
|
// properties
|
|
|
|
public X509CertificateExCollection Certificates {
|
|
get {
|
|
if (_certs == null)
|
|
_certs = new X509CertificateExCollection ();
|
|
return _certs;
|
|
}
|
|
}
|
|
|
|
public StoreLocation Location {
|
|
get { return _location; }
|
|
}
|
|
|
|
public string Name {
|
|
get { return _name; }
|
|
}
|
|
|
|
private bool ReadOnly {
|
|
get { return ((_flags & OpenFlags.ReadOnly) != OpenFlags.ReadOnly); }
|
|
}
|
|
|
|
// methods
|
|
|
|
private static string StoreNameToString (StoreName sn)
|
|
{
|
|
switch (sn) {
|
|
case StoreName.CertificateAuthority:
|
|
return "CA";
|
|
default:
|
|
return sn.ToString ();
|
|
}
|
|
}
|
|
|
|
[MonoTODO ("call Mono.Security.X509.X509Store*")]
|
|
public void Add (X509CertificateEx certificate)
|
|
{
|
|
if (certificate == null)
|
|
throw new ArgumentNullException ("certificate");
|
|
|
|
if (!ReadOnly) {
|
|
try {
|
|
Mono.Security.X509.X509Certificate x = new Mono.Security.X509.X509Certificate (certificate.RawData);
|
|
// TODO
|
|
}
|
|
catch {
|
|
throw new CryptographicException ("couldn't add certificate");
|
|
}
|
|
}
|
|
}
|
|
|
|
public void AddRange (X509CertificateExCollection certificates)
|
|
{
|
|
if (certificates == null)
|
|
throw new ArgumentNullException ("certificates");
|
|
|
|
if (!ReadOnly) {
|
|
foreach (X509CertificateEx certificate in certificates) {
|
|
Add (certificate);
|
|
}
|
|
}
|
|
}
|
|
|
|
[MonoTODO ("call Mono.Security.X509.X509Store*")]
|
|
public void Close ()
|
|
{
|
|
}
|
|
|
|
[MonoTODO ("call Mono.Security.X509.X509Store*")]
|
|
public void Open (OpenFlags flags)
|
|
{
|
|
_flags = flags;
|
|
bool readOnly = ((flags & OpenFlags.ReadOnly) == OpenFlags.ReadOnly);
|
|
bool create = !((flags & OpenFlags.OpenExistingOnly) == OpenFlags.OpenExistingOnly);
|
|
bool archive = ((flags & OpenFlags.IncludeArchived) == OpenFlags.IncludeArchived);
|
|
// TODO
|
|
}
|
|
|
|
[MonoTODO ("call Mono.Security.X509.X509Store*")]
|
|
public void Remove (X509CertificateEx certificate)
|
|
{
|
|
if (certificate == null)
|
|
throw new ArgumentNullException ("certificate");
|
|
|
|
if (!ReadOnly) {
|
|
try {
|
|
Mono.Security.X509.X509Certificate x = new Mono.Security.X509.X509Certificate (certificate.RawData);
|
|
// TODO
|
|
}
|
|
catch {
|
|
throw new CryptographicException ("couldn't remove certificate");
|
|
}
|
|
}
|
|
}
|
|
|
|
public void RemoveRange (X509CertificateExCollection certificates)
|
|
{
|
|
if (certificates == null)
|
|
throw new ArgumentNullException ("certificates");
|
|
|
|
if (!this.ReadOnly) {
|
|
foreach (X509CertificateEx certificate in certificates) {
|
|
Remove (certificate);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|