diff options
Diffstat (limited to 'mobile_src/SecureElement/SEUtil.cpp')
-rw-r--r-- | mobile_src/SecureElement/SEUtil.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/mobile_src/SecureElement/SEUtil.cpp b/mobile_src/SecureElement/SEUtil.cpp new file mode 100644 index 0000000..5d32bce --- /dev/null +++ b/mobile_src/SecureElement/SEUtil.cpp @@ -0,0 +1,110 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + + + +#include "SEUtil.h" +#include <smartcard-types.h> +#include <JSWebAPIErrorFactory.h> +#include <Logger.h> + +namespace DeviceAPI { +namespace SecureElement { + +std::vector<unsigned char> SEUtil::toVector(const unsigned char *ch, const int size) { + std::vector<unsigned char> vec; + if (ch && (size > 0)) { + int i; + + for (i = 0; i < size; i++) + vec.push_back(ch[i]); + } + return vec; +} + + +unsigned char *SEUtil::toCharPtr(std::vector<unsigned char> vec) { + if (vec.size() > 0) { + unsigned char * chr = (unsigned char *) malloc(vec.size() * sizeof(unsigned char)); + for (int i = 0; i < static_cast<int>(vec.size()); i++) + chr[i] = vec.at(i); + + return chr; + } + + return NULL; +} + +std::string SEUtil::getErrorString(const int errorCode) { + LoggerD ("Errorcode : " << errorCode); + switch(errorCode) { + case SCARD_ERROR_OK: + return ""; + case SCARD_ERROR_NOT_ENOUGH_RESOURCE: + return "NoChannelError"; + case SCARD_ERROR_OUT_OF_MEMORY: + case SCARD_ERROR_UNAVAILABLE: + case SCARD_ERROR_IPC_FAILED: + case SCARD_ERROR_OPERATION_TIMEOUT: + case SCARD_ERROR_UNKNOWN: + return DeviceAPI::Common::JSWebAPIErrorFactory::IO_ERROR; + case SCARD_ERROR_ILLEGAL_STATE: + case SCARD_ERROR_ILLEGAL_REFERENCE: + return "InvalidStateError"; + case SCARD_ERROR_ILLEGAL_PARAM: + return DeviceAPI::Common::JSWebAPIErrorFactory::INVALID_VALUES_ERROR; + case SCARD_ERROR_SECURITY_NOT_ALLOWED: + return DeviceAPI::Common::JSWebAPIErrorFactory::SECURITY_ERROR; + case SCARD_ERROR_IO_FAILED: + return DeviceAPI::Common::JSWebAPIErrorFactory::NOT_FOUND_ERROR; + } + return DeviceAPI::Common::JSWebAPIErrorFactory::UNKNOWN_ERROR; +} + +std::string SEUtil::getErrorMessage(const int errorCode) { + LoggerD ("Errorcode : " << errorCode); + switch(errorCode) { + case SCARD_ERROR_OK: + return ""; + case SCARD_ERROR_NOT_ENOUGH_RESOURCE: + return "Not Enough Resource"; + case SCARD_ERROR_OUT_OF_MEMORY: + return "Out Of Memory"; + case SCARD_ERROR_UNAVAILABLE: + return "Unavailable"; + case SCARD_ERROR_IPC_FAILED: + return "Platform Error"; + case SCARD_ERROR_OPERATION_TIMEOUT: + return "Operation Timeout"; + case SCARD_ERROR_UNKNOWN: + return "Unknown Error"; + case SCARD_ERROR_ILLEGAL_STATE: + return "Illegal state"; + case SCARD_ERROR_ILLEGAL_REFERENCE: + return "Illegal reference"; + case SCARD_ERROR_ILLEGAL_PARAM: + return "Illegal param"; + case SCARD_ERROR_SECURITY_NOT_ALLOWED: + return "Security Not Allowed"; + case SCARD_ERROR_IO_FAILED: + return "Not Exist In SE"; + } + return "UnknownError"; +} + +} +} |