| 603 | //----------------------------------------------------------------------------- |
| 604 | |
| 605 | bool CECSigningPublicKey::GetAsOpenSSHAuthorizedKeys( char *pchData, uint32 cubData, uint32 *pcubData, const char *pszComment ) const |
| 606 | { |
| 607 | if ( !IsValid() ) |
| 608 | return false; |
| 609 | |
| 610 | int cchComment = pszComment ? V_strlen( pszComment ) : 0; |
| 611 | |
| 612 | uint8 publicKey[ 32 ]; |
| 613 | VerifyFatal( GetRawData( publicKey ) == 32 ); |
| 614 | |
| 615 | CUtlBuffer bufBinary; |
| 616 | OpenSSHBinaryEd25519WritePublic( bufBinary, publicKey ); |
| 617 | |
| 618 | static const char pchPrefix[] = "ssh-ed25519 "; |
| 619 | |
| 620 | uint32_t uRequiredBytes = |
| 621 | V_strlen( pchPrefix ) |
| 622 | + CCrypto::Base64EncodeMaxOutput( bufBinary.TellPut(), "" ) |
| 623 | + ( cchComment > 0 ? 1 : 0 ) // space |
| 624 | + cchComment |
| 625 | + 1; // '\0' |
| 626 | if ( pcubData ) |
| 627 | *pcubData = uRequiredBytes; |
| 628 | |
| 629 | if ( pchData ) |
| 630 | { |
| 631 | if ( cubData < uRequiredBytes ) |
| 632 | return false; |
| 633 | |
| 634 | V_strncpy( pchData, pchPrefix, cubData ); |
| 635 | uint32_t uRemainingBytes = cubData - V_strlen( pchData ); |
| 636 | |
| 637 | if ( !CCrypto::Base64Encode( (const uint8 *)bufBinary.Base(), bufBinary.TellPut(), pchData + V_strlen( pchData ), &uRemainingBytes, "" ) ) |
| 638 | return false; |
| 639 | |
| 640 | if ( pszComment ) |
| 641 | { |
| 642 | V_strncat( pchData, " ", cubData ); |
| 643 | V_strncat( pchData, pszComment, cubData ); |
| 644 | } |
| 645 | if ( pcubData ) |
| 646 | *pcubData = V_strlen( pchData ) + 1; |
| 647 | } |
| 648 | |
| 649 | return true; |
| 650 | } |
| 651 | |
| 652 | bool CECSigningPublicKey::LoadFromAndWipeBuffer( void *pBuffer, size_t cBytes ) |
| 653 | { |