0b25472e251e0615ed499316abba471ae21c18a3
[mono.git] / mcs / class / referencesource / mscorlib / system / security / cryptography / sha1cryptoserviceprovider.cs
1 // ==++==
2 // 
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6 // <OWNER>Microsoft</OWNER>
7 // 
8
9 //
10 // SHA1CryptoServiceProvider.cs
11 //
12
13 namespace System.Security.Cryptography {
14 [System.Runtime.InteropServices.ComVisible(true)]
15     public sealed class SHA1CryptoServiceProvider : SHA1
16     {
17         [System.Security.SecurityCritical] // auto-generated
18         private SafeHashHandle _safeHashHandle = null;
19
20         //
21         // public constructors
22         //
23       
24         [System.Security.SecuritySafeCritical]  // auto-generated
25         public SHA1CryptoServiceProvider() {
26             // _CreateHash will check for failures and throw the appropriate exception
27             _safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, Constants.CALG_SHA1);
28         }
29
30         [System.Security.SecuritySafeCritical] // overrides public transparent member
31         protected override void Dispose(bool disposing)
32         {
33             if (_safeHashHandle != null && !_safeHashHandle.IsClosed)
34                 _safeHashHandle.Dispose();
35             // call the base class's Dispose
36             base.Dispose(disposing);
37         }
38
39         //
40         // public methods
41         //
42
43         [System.Security.SecuritySafeCritical]  // auto-generated
44         public override void Initialize() {
45             if (_safeHashHandle != null && !_safeHashHandle.IsClosed)
46                 _safeHashHandle.Dispose();
47             
48             // _CreateHash will check for failures and throw the appropriate exception
49             _safeHashHandle = Utils.CreateHash(Utils.StaticProvHandle, Constants.CALG_SHA1);
50         }
51
52         [System.Security.SecuritySafeCritical] // overrides protected transparent member
53         protected override void HashCore(byte[] rgb, int ibStart, int cbSize)
54         {
55             Utils.HashData(_safeHashHandle, rgb, ibStart, cbSize);
56         }
57
58         [System.Security.SecuritySafeCritical] // overrides protected transparent member
59         protected override byte[] HashFinal()
60         {
61             return Utils.EndHash(_safeHashHandle);
62         }
63     }
64 }