Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Account.FidoClient / Tizen.Account.FidoClient / ErrorFactory.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 Tizen.Internals.Errors;
19
20 namespace Tizen.Account.FidoClient
21 {
22     internal enum FidoErrorCode
23     {
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
37     }
38
39     internal class ErrorFactory
40     {
41         internal static string LogTag = "Tizen.Account.FidoClient";
42
43         internal static Exception GetException(int error)
44         {
45             if ((FidoErrorCode)error == FidoErrorCode.OutOfMemory)
46             {
47                 return new OutOfMemoryException("Out of memory");
48             }
49             else if ((FidoErrorCode)error == FidoErrorCode.InvalidParameter)
50             {
51                 return new ArgumentException("Invalid parameter");
52             }
53             else if ((FidoErrorCode)error == FidoErrorCode.UserActionInProgress)
54             {
55                 return new InvalidOperationException("User action already in progress");
56             }
57             else if ((FidoErrorCode)error == FidoErrorCode.NotSupported)
58             {
59                 return new NotSupportedException("FIDO is unsupported.");
60             }
61             else if ((FidoErrorCode)error == FidoErrorCode.PermissionDenied)
62             {
63                 return new UnauthorizedAccessException("Permission denied");
64             }
65             else if ((FidoErrorCode)error == FidoErrorCode.UnsupportedVersion)
66             {
67                 return new NotSupportedException("UAF message's version is not supported.");
68             }
69             else if ((FidoErrorCode)error == FidoErrorCode.NoSuitableAuthenticator)
70             {
71                 return new Exception("Suitable authenticator can't be found");
72             }
73             else if ((FidoErrorCode)error == FidoErrorCode.ProtocolError)
74             {
75                 return new ArgumentException("Protocol error, the interaction may have timed out, or the UAF message is malformed.");
76             }
77             else if ((FidoErrorCode)error == FidoErrorCode.UserCancelled)
78             {
79                 return new Exception("User has canceled the operation.");
80             }
81             else if ((FidoErrorCode)error == FidoErrorCode.UntrustedFacetId)
82             {
83                 return new Exception(" The caller's id is not allowed to use this operation.");
84             }
85             else
86             {
87                 return new Exception("Unknown error");
88             }
89         }
90     }
91 }