7acc37bcd5fb3742902a052327428894fc2f7461
[platform/core/csapi/security.git] / Tizen.Security / Tizen.Security.SecureRepository / Crypto / SignatureParameters.cs
1 /*
2  *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License
15  */
16
17 using System;
18 using System.Collections;
19
20 namespace Tizen.Security.SecureRepository.Crypto
21 {
22     /// <summary>
23     /// A abstract class holding parameters for signing and verification.
24     /// </summary>
25     abstract public class SignatureParameters
26     {
27         private Hashtable _parameters;
28
29         /// <summary>
30         /// A constructor with algorithm
31         /// </summary>
32         /// <param name="algorithm">An algorithm that this parameters are prepared for.</param>
33         protected SignatureParameters(SignatureAlgorithmType algorithm)
34         {
35             _parameters = new Hashtable();
36             Add(SignatureParameterName.AlgorithmType, (int)algorithm);
37         }
38
39         /// <summary>
40         /// Signature algorithm type.
41         /// </summary>
42         public SignatureAlgorithmType SignatureAlgorithm
43         {
44             get { return (SignatureAlgorithmType)Get(SignatureParameterName.AlgorithmType); }
45         }
46
47         /// <summary>
48         /// Hash algorithm used in signing anve verification.
49         /// </summary>
50         public HashAlgorithm HashAlgorithm
51         {
52             get { return (HashAlgorithm)Get(SignatureParameterName.HashAlgorithm); }
53             set { Add(SignatureParameterName.HashAlgorithm, (int)value); }
54         }
55
56         /// <summary>
57         /// Adds integer parameter.
58         /// </summary>
59         /// <param name="name">Parameter name.</param>
60         /// <param name="value">Parameter value.</param>
61         internal void Add(SignatureParameterName name, int value)
62         {
63             _parameters.Add((int)name, value);
64         }
65
66         /// <summary>
67         /// Gets integer parameter.
68         /// </summary>
69         /// <param name="name">Parameter name.</param>
70         internal int Get(SignatureParameterName name)
71         {
72             if (_parameters.ContainsKey((int)name))
73                 return (int)_parameters[(int)name];
74             else
75                 throw new ArgumentException("No parameter for a given SignatureParameterName ");
76         }
77     }
78 }