Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Security.SecureRepository / 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.Generic;
19
20 namespace Tizen.Security.SecureRepository.Crypto
21 {
22     /// <summary>
23     /// A abstract class holding parameters for signing and verification.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     abstract public class SignatureParameters
27     {
28         private Dictionary<SignatureParameterName, int> _parameters;
29
30         /// <summary>
31         /// Signature algorithm type.
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         public SignatureAlgorithmType SignatureAlgorithm
35         {
36             get { return (SignatureAlgorithmType)Get(SignatureParameterName.AlgorithmType); }
37         }
38
39         /// <summary>
40         /// Hash algorithm used in signing anve verification.
41         /// </summary>
42         /// <since_tizen> 3 </since_tizen>
43         public HashAlgorithm HashAlgorithm
44         {
45             get { return (HashAlgorithm)Get(SignatureParameterName.HashAlgorithm); }
46             set { Add(SignatureParameterName.HashAlgorithm, (int)value); }
47         }
48
49         // for inherited in internal only
50         internal SignatureParameters()
51         {
52         }
53
54         internal SignatureParameters(SignatureAlgorithmType algorithm)
55         {
56             _parameters = new Dictionary<SignatureParameterName, int>();
57             Add(SignatureParameterName.AlgorithmType, (int)algorithm);
58         }
59
60         internal void Add(SignatureParameterName name, int value)
61         {
62             _parameters.Add(name, value);
63         }
64
65         internal int Get(SignatureParameterName name)
66         {
67             if (_parameters.ContainsKey(name))
68                 return _parameters[name];
69             else
70                 throw new ArgumentException("No parameter for a given SignatureParameterName ");
71         }
72     }
73 }