MCPcopy Create free account
hub / github.com/SFML/SFML / getSessionInfo

Method getSessionInfo

src/SFML/Network/Sftp.cpp:697–770  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

695
696////////////////////////////////////////////////////////////
697std::optional<Sftp::SessionInfo> Sftp::getSessionInfo() const
698{
699 if (!m_impl->ssh2Session)
700 return std::nullopt;
701
702 SessionInfo sessionInfo;
703
704 {
705 std::size_t length{};
706 auto type = 0;
707 const auto* const ptr = libssh2_session_hostkey(m_impl->ssh2Session.get(), &length, &type);
708
709 if (length == 0)
710 return std::nullopt;
711
712 SessionInfo::HostKey hostKey;
713 hostKey.data.resize(length);
714 std::memcpy(hostKey.data.data(), ptr, length);
715
716 switch (type)
717 {
718 case LIBSSH2_HOSTKEY_TYPE_RSA:
719 hostKey.type = SessionInfo::HostKey::Type::Rsa;
720 break;
721 case LIBSSH2_HOSTKEY_TYPE_DSS:
722 hostKey.type = SessionInfo::HostKey::Type::Dsa;
723 break;
724 case LIBSSH2_HOSTKEY_TYPE_ECDSA_256:
725 hostKey.type = SessionInfo::HostKey::Type::Ecdsa256;
726 break;
727 case LIBSSH2_HOSTKEY_TYPE_ECDSA_384:
728 hostKey.type = SessionInfo::HostKey::Type::Ecdsa384;
729 break;
730 case LIBSSH2_HOSTKEY_TYPE_ECDSA_521:
731 hostKey.type = SessionInfo::HostKey::Type::Ecdsa521;
732 break;
733 case LIBSSH2_HOSTKEY_TYPE_ED25519:
734 hostKey.type = SessionInfo::HostKey::Type::Ed25519;
735 break;
736 default:
737 hostKey.type = SessionInfo::HostKey::Type::Unknown;
738 break;
739 }
740
741 if (const auto* const hash = libssh2_hostkey_hash(m_impl->ssh2Session.get(), LIBSSH2_HOSTKEY_HASH_SHA1); hash)
742 std::memcpy(hostKey.sha1.data(), hash, hostKey.sha1.size());
743
744 if (const auto* const hash = libssh2_hostkey_hash(m_impl->ssh2Session.get(), LIBSSH2_HOSTKEY_HASH_SHA256); hash)
745 std::memcpy(hostKey.sha256.data(), hash, hostKey.sha256.size());
746
747 sessionInfo.hostKey = std::move(hostKey);
748 }
749
750 const auto getSessionMethod = [session = m_impl->ssh2Session.get()](int method) -> std::string
751 {
752 if (!session)
753 return "";
754 if (const auto* const result = libssh2_session_methods(session, method); result)

Callers 2

Sftp.test.cppFile · 0.80
mainFunction · 0.80

Calls 2

getMethod · 0.80
resizeMethod · 0.45

Tested by

no test coverage detected