Skip to content

Commit a62459e

Browse files
authored
Merge pull request #26 from Psiphon-Inc/next-release
v2.4.0
2 parents e96df62 + 9f9aea5 commit a62459e

24 files changed

+1101
-174
lines changed

.github/workflows/build-windows.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# On release, make a Windows release build and attach it to the release
2+
name: Windows Release Build
3+
4+
on:
5+
release:
6+
types: [published]
7+
8+
jobs:
9+
build:
10+
permissions:
11+
# Required for release binary upload
12+
contents: write
13+
14+
runs-on: windows-2019
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- uses: egor-tensin/vs-shell@v2
20+
with:
21+
arch: x86
22+
23+
- name: Run build script
24+
working-directory: ${{env.GITHUB_WORKSPACE}}
25+
run: .\build-windows.bat
26+
27+
- name: Create zip
28+
run: 7z a dist-windows.zip dist-windows
29+
30+
- uses: AButler/[email protected]
31+
with:
32+
files: 'dist-windows.zip'
33+
repo-token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Run test.sh
2+
name: Run Tests
3+
4+
on:
5+
push:
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- run: sudo apt update && sudo apt install -y cmake
17+
18+
- name: test
19+
run: bash ./test.sh

SecretTestValues.h.enc

-1.36 KB
Binary file not shown.

base64.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace base64 {
2323

2424
// From https://stackoverflow.com/a/31322410/729729
2525

26-
static const BYTE from_base64[] = {
26+
static const uint8_t from_base64[] = {
2727
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2828
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
2929
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 62, 255, 63,
@@ -46,13 +46,13 @@ std::string B64Encode(const std::string& buf) {
4646
return B64Encode((const unsigned char*)buf.c_str(), (unsigned int)buf.size());
4747
}
4848

49-
std::string B64Encode(const std::vector<BYTE>& buf) {
49+
std::string B64Encode(const std::vector<uint8_t>& buf) {
5050
if (buf.empty())
5151
return ""; // Avoid dereferencing buf if it's empty
5252
return B64Encode(&buf[0], (unsigned int)buf.size());
5353
}
5454

55-
std::string B64Encode(const BYTE* buf, unsigned int bufLen) {
55+
std::string B64Encode(const uint8_t* buf, unsigned int bufLen) {
5656
// Calculate how many bytes that needs to be added to get a multiple of 3
5757
size_t missing = 0;
5858
size_t ret_size = bufLen;
@@ -70,13 +70,13 @@ std::string B64Encode(const BYTE* buf, unsigned int bufLen) {
7070
for (unsigned int i = 0; i < ret_size / 4; ++i) {
7171
// Read a group of three bytes (avoid buffer overrun by replacing with 0)
7272
size_t index = i * 3;
73-
BYTE b3[3];
73+
uint8_t b3[3];
7474
b3[0] = (index + 0 < bufLen) ? buf[index + 0] : 0;
7575
b3[1] = (index + 1 < bufLen) ? buf[index + 1] : 0;
7676
b3[2] = (index + 2 < bufLen) ? buf[index + 2] : 0;
7777

7878
// Transform into four base 64 characters
79-
BYTE b4[4];
79+
uint8_t b4[4];
8080
b4[0] = ((b3[0] & 0xfc) >> 2);
8181
b4[1] = ((b3[0] & 0x03) << 4) + ((b3[1] & 0xf0) >> 4);
8282
b4[2] = ((b3[1] & 0x0f) << 2) + ((b3[2] & 0xc0) >> 6);
@@ -96,27 +96,27 @@ std::string B64Encode(const BYTE* buf, unsigned int bufLen) {
9696
return ret;
9797
}
9898

99-
std::vector<BYTE> B64Decode(const std::string& b64encoded) {
99+
std::vector<uint8_t> B64Decode(const std::string& b64encoded) {
100100
std::string encoded_string = b64encoded;
101101

102102
// Make sure string length is a multiple of 4
103103
while ((encoded_string.size() % 4) != 0)
104104
encoded_string.push_back('=');
105105

106106
size_t encoded_size = encoded_string.size();
107-
std::vector<BYTE> ret;
107+
std::vector<uint8_t> ret;
108108
ret.reserve(3 * encoded_size / 4);
109109

110110
for (size_t i = 0; i < encoded_size; i += 4) {
111111
// Get values for each group of four base 64 characters
112-
BYTE b4[4];
112+
uint8_t b4[4];
113113
b4[0] = (encoded_string[i + 0] <= 'z') ? from_base64[(size_t)encoded_string[i + 0]] : 0xff;
114114
b4[1] = (encoded_string[i + 1] <= 'z') ? from_base64[(size_t)encoded_string[i + 1]] : 0xff;
115115
b4[2] = (encoded_string[i + 2] <= 'z') ? from_base64[(size_t)encoded_string[i + 2]] : 0xff;
116116
b4[3] = (encoded_string[i + 3] <= 'z') ? from_base64[(size_t)encoded_string[i + 3]] : 0xff;
117117

118118
// Transform into a group of three bytes
119-
BYTE b3[3];
119+
uint8_t b3[3];
120120
b3[0] = ((b4[0] & 0x3f) << 2) + ((b4[1] & 0x30) >> 4);
121121
b3[1] = ((b4[1] & 0x0f) << 4) + ((b4[2] & 0x3c) >> 2);
122122
b3[2] = ((b4[2] & 0x03) << 6) + ((b4[3] & 0x3f) >> 0);

base64.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@
2525

2626
namespace base64 {
2727

28-
typedef unsigned char BYTE;
29-
3028
std::string B64Encode(const std::string& buf);
31-
std::string B64Encode(const std::vector<BYTE>& buf);
32-
std::string B64Encode(const BYTE* buf, unsigned int bufLen);
29+
std::string B64Encode(const std::vector<uint8_t>& buf);
30+
std::string B64Encode(const uint8_t* buf, unsigned int bufLen);
3331

34-
std::vector<BYTE> B64Decode(const std::string& b64encoded);
32+
std::vector<uint8_t> B64Decode(const std::string& b64encoded);
3533

3634
std::string TrimPadding(const std::string& s);
3735

base64_test.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Copyright (c) 2022, Psiphon Inc.
3+
* All rights reserved.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
120
#include "gtest/gtest.h"
221
#include "base64.hpp"
322

@@ -29,54 +48,54 @@ TEST(TestBase64, Encode)
2948
ASSERT_EQ(b64, "Zm9vYmFy");
3049

3150
// The vector overload
32-
vector<BYTE> v;
51+
vector<uint8_t> v;
3352
b64 = B64Encode(v);
3453
ASSERT_EQ(b64, "");
3554

36-
BYTE b[] = "f";
37-
v = vector<BYTE>(b, b+1);
55+
uint8_t b[] = "f";
56+
v = vector<uint8_t>(b, b+1);
3857
b64 = B64Encode(v);
3958
ASSERT_EQ(b64, "Zg==");
4059
}
4160

4261
TEST(TestBase64, Decode)
4362
{
44-
vector<BYTE> v, want;
63+
vector<uint8_t> v, want;
4564
string s;
4665

4766
s = "";
48-
want = vector<BYTE>(s.c_str(), s.c_str()+s.size());
67+
want = vector<uint8_t>(s.c_str(), s.c_str()+s.size());
4968
v = B64Decode("");
5069
ASSERT_EQ(v, want);
5170

5271
s = "fo";
53-
want = vector<BYTE>(s.c_str(), s.c_str()+s.size());
72+
want = vector<uint8_t>(s.c_str(), s.c_str()+s.size());
5473
v = B64Decode("Zm8=");
5574
ASSERT_EQ(v, want);
5675

5776
s = "foo";
58-
want = vector<BYTE>(s.c_str(), s.c_str()+s.size());
77+
want = vector<uint8_t>(s.c_str(), s.c_str()+s.size());
5978
v = B64Decode("Zm9v");
6079
ASSERT_EQ(v, want);
6180

6281
s = "foob";
63-
want = vector<BYTE>(s.c_str(), s.c_str()+s.size());
82+
want = vector<uint8_t>(s.c_str(), s.c_str()+s.size());
6483
v = B64Decode("Zm9vYg==");
6584
ASSERT_EQ(v, want);
6685

6786
s = "fooba";
68-
want = vector<BYTE>(s.c_str(), s.c_str()+s.size());
87+
want = vector<uint8_t>(s.c_str(), s.c_str()+s.size());
6988
v = B64Decode("Zm9vYmE=");
7089
ASSERT_EQ(v, want);
7190

7291
s = "foobar";
73-
want = vector<BYTE>(s.c_str(), s.c_str()+s.size());
92+
want = vector<uint8_t>(s.c_str(), s.c_str()+s.size());
7493
v = B64Decode("Zm9vYmFy");
7594
ASSERT_EQ(v, want);
7695

7796
// Not padded
7897
s = "foob";
79-
want = vector<BYTE>(s.c_str(), s.c_str()+s.size());
98+
want = vector<uint8_t>(s.c_str(), s.c_str()+s.size());
8099
v = B64Decode("Zm9vYg");
81100
ASSERT_EQ(v, want);
82101
}

build-windows.bat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ cmake -G "Visual Studio 16 2019" -A Win32 ..
1616
if "%ERRORLEVEL%" == "1" exit /B 1
1717

1818
REM Build for Debug and MinSizeRel
19-
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat"
19+
REM This doesn't need to be called in the GitHub Action build
20+
if "%GITHUB_ACTION%" == "" call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat"
2021
if "%ERRORLEVEL%" == "1" exit /B 1
2122
msbuild.exe -p:Configuration=Debug -p:PlatformToolset=v140 -p:PreferredToolArchitecture=x86 -p:Platform=x86 -p:PlatformTarget=x86 psicash.vcxproj
2223
if "%ERRORLEVEL%" == "1" exit /B 1

0 commit comments

Comments
 (0)