blob: 6ca06c30b282b6ebf29e94ea14ad81ad4808092b [file] [log] [blame]
//
// Copyright (C) 2011 The Android Open Source Project
//
// 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 "shill/crypto_rot47.h"
#include <string>
#include <gtest/gtest.h>
using std::string;
using testing::Test;
namespace shill {
namespace {
const char kEmpty[] = "";
const char kPlainText[] = "~{\"Hello world!\" OPQ ['1234']}";
const char kCipherText[] = "OLQw6==@ H@C=5PQ ~!\" ,V`abcV.N";
} // namespace
class CryptoRot47Test : public Test {
protected:
CryptoRot47 crypto_;
};
TEST_F(CryptoRot47Test, GetId) {
EXPECT_EQ("rot47", crypto_.GetId());
}
TEST_F(CryptoRot47Test, Encrypt) {
string text;
EXPECT_TRUE(crypto_.Encrypt(kPlainText, &text));
EXPECT_EQ(kCipherText, text);
EXPECT_TRUE(crypto_.Encrypt(kEmpty, &text));
EXPECT_EQ(kEmpty, text);
}
TEST_F(CryptoRot47Test, Decrypt) {
string text;
EXPECT_TRUE(crypto_.Decrypt(kCipherText, &text));
EXPECT_EQ(kPlainText, text);
EXPECT_TRUE(crypto_.Decrypt(kEmpty, &text));
EXPECT_EQ(kEmpty, text);
}
} // namespace shill