Skip to content

Commit 01116ad

Browse files
committed
Cert tool: use vjson, not picojson
1 parent cdb8957 commit 01116ad

2 files changed

Lines changed: 26 additions & 25 deletions

File tree

src/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,13 @@ endif()
380380
#
381381
if (BUILD_TOOLS)
382382

383-
# The cert tool requires picojson.
384-
set(picojson_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/picojson)
385-
check_submodule( ${picojson_SOURCE_DIR} ${picojson_SOURCE_DIR}/picojson.h )
383+
# The cert tool requires vjson.
384+
set(vjson_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/vjson)
385+
check_submodule( ${vjson_SOURCE_DIR} ${vjson_SOURCE_DIR}/vjson.h )
386386

387387
add_executable(steamnetworkingsockets_certtool
388388
"steamnetworkingsockets/certtool/steamnetworkingsockets_certtool.cpp"
389+
${vjson_SOURCE_DIR}/vjson.cpp
389390
)
390391
target_sources(steamnetworkingsockets_certtool PRIVATE
391392
${GNS_COMMON_SRCS}
@@ -397,7 +398,7 @@ if (BUILD_TOOLS)
397398
target_include_directories(steamnetworkingsockets_certtool PUBLIC
398399
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>"
399400
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/GameNetworkingSockets>"
400-
${picojson_SOURCE_DIR}
401+
${vjson_SOURCE_DIR}
401402
)
402403

403404
target_include_directories(steamnetworkingsockets_certtool PRIVATE

src/steamnetworkingsockets/certtool/steamnetworkingsockets_certtool.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <steamdatagram_gamecoordinator.h>
2525
#endif
2626

27-
#include <picojson.h>
27+
#include <vjson.h>
2828

2929
// Really?
3030
#ifdef _WIN32
@@ -101,7 +101,7 @@ int s_nExpiryDays = k_nDefaultExpiryDays;
101101
bool s_bOutputJSON;
102102
bool s_bOutputValveSrcds;
103103
bool s_bOutputTrimWhitespace;
104-
picojson::object s_jsonOutput;
104+
vjson::Object s_jsonOutput;
105105

106106
#ifdef CERTTOOL_ENABLE_SDR
107107
SteamDatagramRelayAuthTicket s_hostedServerTicketProperties;
@@ -263,8 +263,8 @@ static void AddPublicKeyInfoToJSON()
263263
std::string sKeyID = PublicKeyIDAsString();
264264
std::string sComment = "ID"+sKeyID;
265265

266-
s_jsonOutput[ "public_key_id" ] = picojson::value( PublicKeyIDAsString() );
267-
s_jsonOutput[ "public_key" ] = picojson::value( PublicKeyAsAuthorizedKeys() );
266+
s_jsonOutput[ "public_key_id" ] = PublicKeyIDAsString();
267+
s_jsonOutput[ "public_key" ] = PublicKeyAsAuthorizedKeys();
268268
}
269269

270270
void GenKeyPair()
@@ -319,7 +319,7 @@ void GenKeyPair()
319319
else
320320
Printf( "%s\n", text );
321321

322-
s_jsonOutput[ "private_key" ] = picojson::value( text );
322+
s_jsonOutput[ "private_key" ] = text;
323323

324324
// Round trip sanity check
325325
{
@@ -332,7 +332,7 @@ void GenKeyPair()
332332
static const char k_szSDRCertPEMHeader[] = "-----BEGIN STEAMDATAGRAM CERT-----";
333333
static const char k_szSDRCertPEMFooter[] = "-----END STEAMDATAGRAM CERT-----";
334334

335-
void PrintCertInfo( const CMsgSteamDatagramCertificateSigned &msgSigned, picojson::object &outJSON )
335+
void PrintCertInfo( const CMsgSteamDatagramCertificateSigned &msgSigned, vjson::Object &outJSON )
336336
{
337337
char szTemp[ 256 ];
338338

@@ -356,47 +356,47 @@ void PrintCertInfo( const CMsgSteamDatagramCertificateSigned &msgSigned, picojso
356356

357357
std::string sPOPIDs;
358358
{
359-
picojson::array pop_ids;
359+
vjson::Array pop_ids;
360360
for ( SteamNetworkingPOPID id: msgCert.gameserver_datacenter_ids() )
361361
{
362362
GetSteamNetworkingLocationPOPStringFromID( id, szTemp );
363363

364364
if ( !sPOPIDs.empty() )
365365
sPOPIDs += ' ';
366366
sPOPIDs += szTemp;
367-
pop_ids.push_back( picojson::value( szTemp ) );
367+
pop_ids.push_back( szTemp );
368368
}
369369
if ( !pop_ids.empty() )
370370
{
371-
outJSON[ "pop_ids" ] = picojson::value( pop_ids );
371+
outJSON[ "pop_ids" ] = pop_ids;
372372
}
373373
}
374374

375375
std::string sAppIDs;
376376
{
377-
picojson::array app_ids;
377+
vjson::Array app_ids;
378378
for ( AppId_t id: msgCert.app_ids() )
379379
{
380380
V_sprintf_safe( szTemp, "%u", id );
381381

382382
if ( !sAppIDs.empty() )
383383
sAppIDs += ' ';
384384
sAppIDs += szTemp;
385-
app_ids.push_back( picojson::value( (double)id ) );
385+
app_ids.push_back( (double)id );
386386
}
387387
if ( !app_ids.empty() )
388388
{
389-
outJSON[ "app_ids" ] = picojson::value( app_ids );
389+
outJSON[ "app_ids" ] = app_ids;
390390
}
391391
}
392392

393393
uint64 key_id = CalculatePublicKeyID( pubKey );
394394

395-
outJSON[ "time_created" ] = picojson::value( (double)timeCreated );
396-
outJSON[ "time_created_string" ] = picojson::value( szTimeCreated );
397-
outJSON[ "time_expiry" ] = picojson::value( (double)timeExpiry );
398-
outJSON[ "time_expiry_string" ] = picojson::value( szTimeExpiry );
399-
outJSON[ "ca_key_id" ] = picojson::value( KeyIDAsString( msgSigned.ca_key_id() ) );
395+
outJSON[ "time_created" ] = (double)timeCreated;
396+
outJSON[ "time_created_string" ] = szTimeCreated;
397+
outJSON[ "time_expiry" ] = (double)timeExpiry;
398+
outJSON[ "time_expiry_string" ] = szTimeExpiry;
399+
outJSON[ "ca_key_id" ] = KeyIDAsString( msgSigned.ca_key_id() );
400400

401401
Printf( "#Public key . . . : %s ID%s\n", PublicKeyAsAuthorizedKeys( pubKey ).c_str(), KeyIDAsString( key_id ).c_str() );
402402
Printf( "#Created. . . . . : %s (%llu)\n", szTimeCreated, (unsigned long long)timeCreated );
@@ -458,7 +458,7 @@ void CreateCert()
458458
Printf( "%s", pem.c_str() );
459459

460460
std::string pem_json = Base64EncodeProtobuf( msgSigned, "" );
461-
s_jsonOutput[ "cert" ] = picojson::value( pem_json );
461+
s_jsonOutput[ "cert" ] = pem_json;
462462

463463
PrintCertInfo( msgSigned, s_jsonOutput );
464464
}
@@ -478,7 +478,7 @@ void PrintDHKey( const TCryptoKey &key, const char *pszPlainTextHeader, const ch
478478
DbgVerify( CCrypto::HexEncode( bufTemp.Base(), cbRaw, pszHex, cbText ) );
479479

480480
Printf( "%s: %s\n", pszPlainTextHeader, pszHex );
481-
s_jsonOutput[ pszJSON ] = picojson::value( pszHex );
481+
s_jsonOutput[ pszJSON ] = pszHex;
482482

483483
// !TEST! Round-trip to make sure we are working
484484
TCryptoKey keyCheck;
@@ -541,7 +541,7 @@ void CreateHostedServerTicket()
541541

542542
std::string ticket_base64 = Base64EncodeProtobuf( msgSignedTicket, "" );
543543
Printf( "SDR_DEVTICKET=%s\n", ticket_base64.c_str() );
544-
s_jsonOutput[ "ticket" ] = picojson::value( ticket_base64 );
544+
s_jsonOutput[ "ticket" ] = ticket_base64;
545545
}
546546

547547
#endif
@@ -774,7 +774,7 @@ int main( int argc, char **argv )
774774

775775
if ( s_bOutputJSON )
776776
{
777-
puts( picojson::value( s_jsonOutput ).serialize( true ).c_str() );
777+
puts( s_jsonOutput.PrintJSON().c_str() );
778778
}
779779

780780
return 0;

0 commit comments

Comments
 (0)