Fix project files to support netstandard 1.6
[platform/core/csapi/tizenfx.git] / src / Tizen.Security.SecureRepository / Tizen.Security.SecureRepository / SafeAliasListHandle.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 using System.Runtime.InteropServices;
20 using static Interop;
21
22 namespace Tizen.Security.SecureRepository
23 {
24     internal class SafeAliasListHandle : SafeHandle
25     {
26         public SafeAliasListHandle(IntPtr ptrAliases, bool ownsHandle = true) : base(IntPtr.Zero, ownsHandle)
27         {
28             base.SetHandle(ptrAliases);
29
30             List<string> aliases = new List<string>();
31             while (ptrAliases != IntPtr.Zero)
32             {
33                 CkmcAliasList ckmcAliasList = (CkmcAliasList)Marshal.PtrToStructure(ptrAliases, typeof(CkmcAliasList));
34                 aliases.Add(Marshal.PtrToStringAnsi(ckmcAliasList.alias));
35                 ptrAliases = ckmcAliasList.next;
36             }
37
38             this.Aliases = aliases;
39         }
40
41         public List<string> Aliases
42         {
43             get; set;
44         }
45
46         /// <summary>
47         /// Gets a value that indicates whether the handle is invalid.
48         /// </summary>
49         public override bool IsInvalid
50         {
51             get { return handle == IntPtr.Zero; }
52         }
53
54         /// <summary>
55         /// When overridden in a derived class, executes the code required to free the handle.
56         /// </summary>
57         /// <returns>true if the handle is released successfully</returns>
58         protected override bool ReleaseHandle()
59         {
60             if (IsInvalid) // do not release
61                 return true;
62
63             Interop.CkmcTypes.AliasListAllFree(handle);
64             this.SetHandle(IntPtr.Zero);
65             return true;
66         }
67     }
68 }