2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
18 using System.Collections.Generic;
19 using System.Runtime.InteropServices;
22 namespace Tizen.Security.SecureRepository
24 internal class SafeAliasListHandle : SafeHandle
26 public SafeAliasListHandle(IntPtr ptrAliases, bool ownsHandle = true) : base(IntPtr.Zero, ownsHandle)
28 base.SetHandle(ptrAliases);
30 List<string> aliases = new List<string>();
31 while (ptrAliases != IntPtr.Zero)
33 CkmcAliasList ckmcAliasList = (CkmcAliasList)Marshal.PtrToStructure(ptrAliases, typeof(CkmcAliasList));
34 aliases.Add(Marshal.PtrToStringAnsi(ckmcAliasList.alias));
35 ptrAliases = ckmcAliasList.next;
38 this.Aliases = aliases;
41 public List<string> Aliases
47 /// Gets a value that indicates whether the handle is invalid.
49 public override bool IsInvalid
51 get { return handle == IntPtr.Zero; }
55 /// When overridden in a derived class, executes the code required to free the handle.
57 /// <returns>true if the handle is released successfully</returns>
58 protected override bool ReleaseHandle()
60 if (IsInvalid) // do not release
63 Interop.CkmcTypes.AliasListAllFree(handle);
64 this.SetHandle(IntPtr.Zero);