Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Security.SecureRepository / Tizen.Security.SecureRepository / Manager.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
19 namespace Tizen.Security.SecureRepository
20 {
21     /// <summary>
22     /// This class is a base class of XxxManager classes. It provides the common methods
23     /// for all sub classes.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     public class Manager
27     {
28         /// <summary>
29         /// Creates a new full alias which is concatenation of owner id and alias.
30         /// </summary>
31         /// <since_tizen> 3 </since_tizen>
32         /// <param name="ownerId">Data owner's id. This should be package id if data
33         /// owner is application. If you want to access data stored by system services,
34         /// use CreateFullSystemAlias() instead.</param>
35         /// <param name="alias">Data alias.</param>
36         static public string CreateFullAlias(string ownerId, string alias)
37         {
38             return ownerId + Manager.OwnerIdSeperator + alias;
39         }
40
41         /// <summary>
42         /// Creates a new full alias which is concatenation of system service's
43         /// owner id and alias.
44         /// </summary>
45         /// <since_tizen> 3 </since_tizen>
46         /// <param name="alias">Data alias which is owned by system service.</param>
47         static public string CreateFullSystemAlias(string alias)
48         {
49             return Manager.CreateFullAlias(Manager.SystemOwnerId, alias);
50         }
51
52         /// <summary>
53         /// Removes a an entry (no matter of type) from the key manager.
54         /// </summary>
55         /// <since_tizen> 3 </since_tizen>
56         /// <param name="alias">Item alias to be removed.</param>
57         /// <exception cref="ArgumentNullException">alias is null.</exception>
58         /// <exception cref="ArgumentException">alias is invalid format.</exception>
59         /// <exception cref="InvalidOperationException">alias does not exist.</exception>
60         /// <remarks>
61         /// To remove item, client must have remove permission to the specified item.
62         /// </remarks>
63         /// <remarks>The item owner can remove by default.</remarks>
64         static public void RemoveAlias(string alias)
65         {
66             if (alias == null)
67                 throw new ArgumentNullException("alias should not be null");
68
69             Interop.CheckNThrowException(
70                 Interop.CkmcManager.RemoveAlias(alias),
71                 "Failed to remove alias. alias=" + alias);
72         }
73
74         /// <summary>
75         /// Allows another application to access client's application data.
76         /// </summary>
77         /// <since_tizen> 3 </since_tizen>
78         /// <param name="alias">Item alias for which access will be granted.</param>
79         /// <param name="otherPackageId">
80         /// Package id of the application that will gain access rights.
81         /// </param>
82         /// <param name="permissions">
83         /// Mask of permissions(Permission enum) granted for an application with
84         /// otherPackageId.
85         /// </param>
86         /// <exception cref="ArgumentNullException">
87         /// alias or otherPackageId is null.
88         /// </exception>
89         /// <exception cref="ArgumentException">
90         /// alias or otherPackageId is invalid format.
91         /// </exception>
92         /// <exception cref="InvalidOperationException">alias does not exist.</exception>
93         /// <remarks>Data identified by alias should exist.</remarks>
94         /// <remarks>The item owner can set permissions.</remarks>
95         static public void SetPermission(
96             string alias, string otherPackageId, int permissions)
97         {
98             if (alias == null || otherPackageId == null)
99                 throw new ArgumentNullException("alias or otherPackageId is null");
100
101             Interop.CheckNThrowException(
102                 Interop.CkmcManager.SetPermission(alias, otherPackageId, permissions),
103                 "Failed to set permission. alias=" + alias);
104         }
105
106         // to being static base class
107         internal Manager()
108         {
109         }
110
111         private const string OwnerIdSeperator = " ";
112         private const string SystemOwnerId = "/System";
113     }
114 }