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 Tizen.Internals.Errors;
20 namespace Tizen.Account.FidoClient
22 internal enum FidoErrorCode
24 None = ErrorCode.None,
25 OutOfMemory = ErrorCode.OutOfMemory,
26 InvalidParameter = ErrorCode.InvalidParameter,
27 NoData = ErrorCode.NoData,
28 NotSupported = ErrorCode.NotSupported,
29 PermissionDenied = ErrorCode.PermissionDenied,
30 UserActionInProgress = -0x01030000 | 0x01,
31 UserCancelled = -0x01030000 | 0x02,
32 UnsupportedVersion = -0x01030000 | 0x03,
33 NoSuitableAuthenticator = -0x01030000 | 0x04,
34 ProtocolError = -0x01030000 | 0x05,
35 UntrustedFacetId = -0x01030000 | 0x06,
36 Unknown = ErrorCode.Unknown
39 internal class ErrorFactory
41 internal static string LogTag = "Tizen.Account.FidoClient";
43 internal static Exception GetException(int error)
45 if ((FidoErrorCode)error == FidoErrorCode.OutOfMemory)
47 return new OutOfMemoryException("Out of memory");
49 else if ((FidoErrorCode)error == FidoErrorCode.InvalidParameter)
51 return new ArgumentException("Invalid parameter");
53 else if ((FidoErrorCode)error == FidoErrorCode.UserActionInProgress)
55 return new InvalidOperationException("User action already in progress");
57 else if ((FidoErrorCode)error == FidoErrorCode.NotSupported)
59 return new NotSupportedException("FIDO is unsupported.");
61 else if ((FidoErrorCode)error == FidoErrorCode.PermissionDenied)
63 return new UnauthorizedAccessException("Permission denied");
65 else if ((FidoErrorCode)error == FidoErrorCode.UnsupportedVersion)
67 return new NotSupportedException("UAF message's version is not supported.");
69 else if ((FidoErrorCode)error == FidoErrorCode.NoSuitableAuthenticator)
71 return new Exception("Suitable authenticator can't be found");
73 else if ((FidoErrorCode)error == FidoErrorCode.ProtocolError)
75 return new ArgumentException("Protocol error, the interaction may have timed out, or the UAF message is malformed.");
77 else if ((FidoErrorCode)error == FidoErrorCode.UserCancelled)
79 return new Exception("User has canceled the operation.");
81 else if ((FidoErrorCode)error == FidoErrorCode.UntrustedFacetId)
83 return new Exception(" The caller's id is not allowed to use this operation.");
87 return new Exception("Unknown error");