Initial commit
[mono.git] / mcs / class / referencesource / mscorlib / system / security / cryptography / randomnumbergenerator.cs
1 // ==++==
2 // 
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6 // <OWNER>[....]</OWNER>
7 // 
8
9 //
10 // RandomNumberGenerator.cs
11 //
12
13 namespace System.Security.Cryptography {
14 #if !FEATURE_CORECLR && !SILVERLIGHT
15 [System.Runtime.InteropServices.ComVisible(true)]
16 #endif // !FEATURE_CORECLR && !SILVERLIGHT
17     public abstract class RandomNumberGenerator
18     // On Orcas RandomNumberGenerator is not disposable, so we cannot add the IDisposable implementation to the
19     // CoreCLR mscorlib.  However, this type does need to be disposable since subtypes can and do hold onto
20     // native resources. Therefore, on desktop mscorlibs we add an IDisposable implementation.
21 #if !FEATURE_CORECLR
22     : IDisposable
23 #endif // !FEATURE_CORECLR
24     {
25         protected RandomNumberGenerator() {
26         }
27     
28         //
29         // public methods
30         //
31
32 #if (!FEATURE_CORECLR && !SILVERLIGHT) || FEATURE_LEGACYNETCFCRYPTO
33         static public RandomNumberGenerator Create() {
34             return Create("System.Security.Cryptography.RandomNumberGenerator");
35         }
36
37         static public RandomNumberGenerator Create(String rngName) {
38             return (RandomNumberGenerator) CryptoConfig.CreateFromName(rngName);
39         }
40 #endif // (!FEATURE_CORECLR && !SILVERLIGHT) || FEATURE_LEGACYNETCFCRYPTO
41
42         public void Dispose() {
43             Dispose(true);
44             GC.SuppressFinalize(this);
45         }
46
47         protected virtual void Dispose(bool disposing) {
48             return;
49         }
50
51         public abstract void GetBytes(byte[] data);
52
53 #if (!FEATURE_CORECLR && !SILVERLIGHT) || FEATURE_LEGACYNETCFCRYPTO
54         public virtual void GetNonZeroBytes(byte[] data)
55         {
56             // This method does not exist on Silverlight, so for compatibility we cannot have it be abstract
57             // on the desktop (otherwise any type deriving from RandomNumberGenerator on Silverlight cannot
58             // compile against the desktop CLR).  Since this technically is an abstract method with no
59             // implementation, we'll just throw NotImplementedException.
60             throw new NotImplementedException();
61         }
62 #endif // (!FEATURE_CORECLR && !SILVERLIGHT) || FEATURE_LEGACYNETCFCRYPTO
63     }
64 }