1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "mms_base64.h" 17 18 #include <glib.h> 19 #include <glib/gi18n.h> 20 21 #include "securec.h" 22 23 namespace OHOS { 24 namespace Telephony { Encode(const std::string src)25std::string MmsBase64::Encode(const std::string src) 26 { 27 gchar *encode_data = g_base64_encode((guchar *)src.data(), src.length()); 28 if (encode_data == nullptr) { 29 return ""; 30 } 31 gsize out_len = 0; 32 out_len = strlen(encode_data); 33 std::string dest((char *)encode_data, out_len); 34 if (encode_data != nullptr) { 35 g_free(encode_data); 36 } 37 return dest; 38 } 39 Decode(const std::string src)40std::string MmsBase64::Decode(const std::string src) 41 { 42 gsize out_len = 0; 43 char *decode_data = (char *)g_base64_decode(src.data(), &out_len); 44 if (decode_data == nullptr) { 45 return ""; 46 } 47 std::string dest(decode_data, out_len); 48 if (decode_data != nullptr) { 49 g_free(decode_data); 50 } 51 return dest; 52 } 53 } // namespace Telephony 54 } // namespace OHOS 55