# ne7ssh_string.h

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005-2007 by NetSieben Technologies INC                 *
    00003  *   Author: Andrew Useckas                                                *
    00004  *   Email: andrew@netsieben.com                                           *
    00005  *                                                                         *
    00006  *   Windows Port and bugfixes: Keef Aragon <keef@netsieben.com>           *
    00007  *                                                                         *
    00008  *   This program may be distributed under the terms of the Q Public       *
    00009  *   License as defined by Trolltech AS of Norway and appearing in the     *
    00010  *   file LICENSE.QPL included in the packaging of this file.              *
    00011  *                                                                         *
    00012  *   This program is distributed in the hope that it will be useful,       *
    00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  *
    00015  ***************************************************************************/
    00016
    00017 #ifndef NE7SSH_STRING_H
    00018 #define NE7SSH_STRING_H
    00019
    00020 #include "ne7ssh_types.h"
    00021 #include <botan/bigint.h>
    00022
    00026 class ne7ssh_string
    00027 {
    00028 private:
    00029   Botan::byte **positions;
    00030   uint32 parts;
    00031   uint32 currentPart;
    00032
    00033 protected:
    00034   Botan::SecureVector<Botan::byte> buffer;
    00035
    00036 public:
    00041     ne7ssh_string();
    00042
    00049     ne7ssh_string(Botan::SecureVector<Botan::byte>& var, uint32 position);
    00050
    00056     ne7ssh_string(const char* var, uint32 position);
    00057
    00061     virtual ~ne7ssh_string();
    00062
    00066     void clear() { buffer.destroy(); }
    00067
    00074     void addString (const char* str);
    00075
    00081     bool addFile (const char* filename);
    00082
    00088     void addBytes (const Botan::byte* buff, uint32 len);
    00089
    00094     void addVector (Botan::SecureVector<Botan::byte>& secvec);
    00095
    00102     void addVectorField (const Botan::SecureVector<Botan::byte>& vector);
    00103
    00108     void addChar (const char ch);
    00109
    00115     void addInt (const uint32 var);
    00116
    00123     void addBigInt (const Botan::BigInt& bn);
    00124
    00129     virtual Botan::SecureVector<Botan::byte> &value () { return buffer; }
    00130
    00135     uint32 length () { return buffer.size(); }
    00136
    00142     bool getString (Botan::SecureVector<Botan::byte>& result);
    00143
    00149     bool getBigInt (Botan::BigInt& result);
    00150
    00155     uint32 getInt ();
    00156
    00161     Botan::byte getByte ();
    00162
    00167     void split (const char token);
    00168
    00172     void resetParts () { currentPart = 0; }
    00173
    00178     char* nextPart ();
    00179
    00184     void chop (uint32 nBytes);
    00185
    00192     static void bn2vector (Botan::SecureVector<Botan::byte>& result, const Botan::BigInt& bi);
    00193
    00194 };
    00195
    00196 #endif