+ All Categories
Home > Documents > Solid C++ by Examples

Solid C++ by Examples

Date post: 06-Apr-2018
Category:
Upload: boundex
View: 220 times
Download: 0 times
Share this document with a friend

of 204

Transcript
  • 8/3/2019 Solid C++ by Examples

    1/204

  • 8/3/2019 Solid C++ by Examples

    2/204

    namespace bar {

    class Foo {int _value;int my_magic(int a, int b);

    public:

    Foo(int seed);int calc(int number = 7);int getValue() {return _value;

    }void print(char* prefix);

    };

    }

    ~/myprog/foo.hpp

  • 8/3/2019 Solid C++ by Examples

    3/204

    namespace bar {

    class Foo {int _value;int my_magic(int a, int b);

    public:

    Foo(int seed);int calc(int number = 7);int getValue() {return _value;

    }void print(char* prefix);

    };

    }

    ~/myprog/foo.hpp

  • 8/3/2019 Solid C++ by Examples

    4/204

    namespace bar {

    class Foo {int _value;int my_magic(int a, int b);

    public:

    Foo(int seed);int calc(int number = 7);int getValue() {return _value;

    }void print(char* prefix);

    };

    }

    ~/myprog/foo.hpp

    Solid code?

  • 8/3/2019 Solid C++ by Examples

    5/204

    namespace bar {

    class Foo {int _value;int my_magic(int a, int b);

    public:

    Foo(int seed);int calc(int number = 7);int getValue() {return _value;

    }void print(char* prefix);

    };

    }

    ~/myprog/foo.hpp

  • 8/3/2019 Solid C++ by Examples

    6/204

    namespace bar {

    class Foo {int _value;int my_magic(int a, int b);

    public:

    Foo(int seed);int calc(int number = 7);int getValue() {return _value;

    }void print(char* prefix);

    };

    }

    ~/myprog/foo.hpp

    Bad code?

  • 8/3/2019 Solid C++ by Examples

    7/204

    namespace bar {

    class Foo {int _value;int my_magic(int a, int b);

    public:

    Foo(int seed);int calc(int number = 7);int getValue() {return _value;

    }void print(char* prefix);

    };

    }

    ~/myprog/foo.hpp

  • 8/3/2019 Solid C++ by Examples

    8/204

    PAL - a Primitive Authentication Library in C++ for educational purposes

    http://github.com/olvemaudal/pal

    (from the README file)

    Here is the main "use story":

    As a client, when prompted for ntlm authentication by the server, I want a tool/library that can help meto create the initial ntlm request (type 1 message) that I can send to the server to receive a challenge

    (type 2 message) that needs to be solved by applying my username and password to create an ntlmresponse that I can send to the server. (phew...)

    Here are some (imaginary) additional requirements:- must be in C or C++, since embeeded- it should be possible and convenient to create a

  • 8/3/2019 Solid C++ by Examples

    9/204

    1. base classes should have virtual destructors2. header files should have header guards3. make sure you include the proper header files, especially in header files

    4. no need to include files included by the base class declaration5. single argument constructors should be specified as explicit6. focus on usage of class; public stuff first, then private stuff7. always focus on readability, you spend more time reading code than writing it8. importing a namespace in implementation files is usually not a good idea9. "never" import a namespace in a header file10. initialize objects properly, use the initialization list

    11. prefer std::size_t when working with memory indexing and offsets12. for non-trivial objects, prefer pass by const over pass by copy13. query methods should be specified as const14. order the include files like this; own, project/platform, standard15. avoid magic numbers, use explaination variables16. avoid superfluous use of ()17. prefer forward declarations when you can

    18. do not use explicit on multi argument constructors19. consider explainability, don't do things that needs elaborate explainations20. avoid default arguments (they are often not used anyway)21. do not throw pointers to exceptions (eg, not "throw new ...")22. treat warnings like errors (-Werror) and compile with high warning levels (-Wall -Wextra)23. consider using -Weffc++ and -pedantic as well24. do not mess with borrowed things

    25. always consider the sideeffects of what you do

    Issues discussed here

  • 8/3/2019 Solid C++ by Examples

    10/204

  • 8/3/2019 Solid C++ by Examples

    11/204

  • 8/3/2019 Solid C++ by Examples

    12/204

    ntlm_message.hpp

  • 8/3/2019 Solid C++ by Examples

    13/204

    #include

    namespace pal {

    class ntlm_message {public:

    virtual std::vector as_bytes() const = 0;};

    }

  • 8/3/2019 Solid C++ by Examples

    14/204

    #include

    namespace pal {

    class ntlm_message {public:

    virtual std::vector as_bytes() const = 0;};

    }

    Find 3 issues

  • 8/3/2019 Solid C++ by Examples

    15/204

    #include

    namespace pal {

    class ntlm_message {public:

    virtual std::vector as_bytes() const = 0;};

    }

  • 8/3/2019 Solid C++ by Examples

    16/204

    #include

    namespace pal {

    class ntlm_message {public:

    virtual std::vector as_bytes() const = 0;};

    }

    WTF? This class must have a

    virtual destructor!

  • 8/3/2019 Solid C++ by Examples

    17/204

    #include

    namespace pal {

    class ntlm_message {public:

    virtual std::vector as_bytes() const = 0;};

    }

  • 8/3/2019 Solid C++ by Examples

    18/204

    #include

    namespace pal {

    class ntlm_message {public:

    virtual std::vector as_bytes() const = 0;};

    }

    missing header guard

  • 8/3/2019 Solid C++ by Examples

    19/204

    #include

    namespace pal {

    class ntlm_message {public:

    virtual std::vector as_bytes() const = 0;};

    }

  • 8/3/2019 Solid C++ by Examples

    20/204

    #include

    namespace pal {

    class ntlm_message {public:

    virtual std::vector as_bytes() const = 0;};

    }

    should include

  • 8/3/2019 Solid C++ by Examples

    21/204

    #include

    namespace pal {

    class ntlm_message {public:

    virtual std::vector as_bytes() const = 0;};

    }

  • 8/3/2019 Solid C++ by Examples

    22/204

    #include

    namespace pal {

    class ntlm_message {public:

    virtual std::vector as_bytes() const = 0;};

    }

    #ifndef PAL_NTLM_MESSAGE_HPP_INCLUDED#define PAL_NTLM_MESSAGE_HPP_INCLUDED

    #endif

  • 8/3/2019 Solid C++ by Examples

    23/204

    #ifndef PAL_NTLM_MESSAGE_HPP_INCLUDED#define PAL_NTLM_MESSAGE_HPP_INCLUDED

    #include

    namespace pal {

    class ntlm_message {public:

    virtual std::vector as_bytes() const = 0;

    };}

    #endif

  • 8/3/2019 Solid C++ by Examples

    24/204

    virtual ~ntlm_message() {}

    #ifndef PAL_NTLM_MESSAGE_HPP_INCLUDED#define PAL_NTLM_MESSAGE_HPP_INCLUDED

    #include

    namespace pal {

    class ntlm_message {public:

    virtual std::vector as_bytes() const = 0;

    };}

    #endif

  • 8/3/2019 Solid C++ by Examples

    25/204

    #ifndef PAL_NTLM_MESSAGE_HPP_INCLUDED#define PAL_NTLM_MESSAGE_HPP_INCLUDED

    #include

    namespace pal {

    class ntlm_message {public:

    virtual ~ntlm_message() {}

    virtual std::vector as_bytes() const = 0;};}

    #endif

  • 8/3/2019 Solid C++ by Examples

    26/204

    #ifndef PAL_NTLM_MESSAGE_HPP_INCLUDED#define PAL_NTLM_MESSAGE_HPP_INCLUDED

    #include

    namespace pal {

    class ntlm_message {public:

    virtual ~ntlm_message() {}

    virtual std::vector as_bytes() const = 0;};}

    #endif

    #include

  • 8/3/2019 Solid C++ by Examples

    27/204

    #ifndef PAL_NTLM_MESSAGE_HPP_INCLUDED#define PAL_NTLM_MESSAGE_HPP_INCLUDED

    #include

    namespace pal {

    class ntlm_message {public:

    virtual ~ntlm_message() {}

    virtual std::vector as_bytes() const = 0;};}

    #endif

    #include

  • 8/3/2019 Solid C++ by Examples

    28/204

    #ifndef PAL_NTLM_MESSAGE_HPP_INCLUDED#define PAL_NTLM_MESSAGE_HPP_INCLUDED

    #include

    namespace pal {

    class ntlm_message {public:

    virtual ~ntlm_message() {}virtual std::vector as_bytes() const = 0;

    };}

    #endif

    #include

    This is Solid C++!

  • 8/3/2019 Solid C++ by Examples

    29/204

    type1_message.hpp

  • 8/3/2019 Solid C++ by Examples

    30/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {uint32_t ssp_flags_;

    public:type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    };}

    #endif

    #include

  • 8/3/2019 Solid C++ by Examples

    31/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {uint32_t ssp_flags_;

    public:type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    };}

    #endif

    #include

    Find 3 issues

  • 8/3/2019 Solid C++ by Examples

    32/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {uint32_t ssp_flags_;

    public:type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    };}

    #endif

    #include

  • 8/3/2019 Solid C++ by Examples

    33/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {uint32_t ssp_flags_;

    public:type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    };}

    #endif

    #include

    no need to include again

  • 8/3/2019 Solid C++ by Examples

    34/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {uint32_t ssp_flags_;

    public:type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    };}

    #endif

    #include

  • 8/3/2019 Solid C++ by Examples

    35/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {uint32_t ssp_flags_;

    public:type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    };}

    #endif

    #include

    focus on usage;

    public stuff first, thenprivate stuff

  • 8/3/2019 Solid C++ by Examples

    36/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {uint32_t ssp_flags_;

    public:type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    };}

    #endif

    #include

  • 8/3/2019 Solid C++ by Examples

    37/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {uint32_t ssp_flags_;

    public:type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    };}

    #endif

    #include

    single argument

    constructors shouldnearly always have theexplicit specifier

  • 8/3/2019 Solid C++ by Examples

    38/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    #include

    namespace pal {

    class type1_message : public ntlm_message {uint32_t ssp_flags_;

    public:type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    };}

    #endif

  • 8/3/2019 Solid C++ by Examples

    39/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {uint32_t ssp_flags_;

    public:type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    };}

    #endif

  • 8/3/2019 Solid C++ by Examples

    40/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {

    uint32_t ssp_flags_;public:

    type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    };}

    #endif

  • 8/3/2019 Solid C++ by Examples

    41/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {

    uint32_t ssp_flags_;public:

    type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    };}

    #endif

    private:

  • 8/3/2019 Solid C++ by Examples

    42/204

    public:type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {

    };}

    #endif

    private:uint32_t ssp_flags_;

  • 8/3/2019 Solid C++ by Examples

    43/204

    public:type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {

    };}

    #endif

    private:uint32_t ssp_flags_;

  • 8/3/2019 Solid C++ by Examples

    44/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {public:

    virtual std::vector as_bytes() const;private:

    uint32_t ssp_flags_;};

    }

    #endif

    type1_message(uint32_t ssp_flags);

  • 8/3/2019 Solid C++ by Examples

    45/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {public:

    virtual std::vector as_bytes() const;private:

    uint32_t ssp_flags_;};

    }

    #endif

    type1_message(uint32_t ssp_flags); explicit

  • 8/3/2019 Solid C++ by Examples

    46/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {public:

    explicit type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    private:uint32_t ssp_flags_;

    };}

    #endif

  • 8/3/2019 Solid C++ by Examples

    47/204

    #ifndef PAL_TYPE1_MESSAGE_HPP_INCLUDED#define PAL_TYPE1_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type1_message : public ntlm_message {public:

    explicit type1_message(uint32_t ssp_flags);virtual std::vector as_bytes() const;

    private:uint32_t ssp_flags_;

    };}

    #endif Looks good!

  • 8/3/2019 Solid C++ by Examples

    48/204

    type1_message.cpp

    #include "type1_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    49/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    using namespace std;

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return vector(message, message + sizeof message);}

    #include "type1_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    50/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    using namespace std;

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return vector(message, message + sizeof message);}

    Find at least 3issues here

    #include "type1_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    51/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    using namespace std;

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return vector(message, message + sizeof message);}

    #include "type1_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    52/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    using namespace std;

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return vector(message, message + sizeof message);}

    focus on readability;importing a namespace might

    save some keystrokes, but oftenit does not increase readability

    #include "type1_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    53/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    using namespace std;

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return vector(message, message + sizeof message);}

    #include "type1_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    54/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    using namespace std;

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return vector(message, message + sizeof message);}

    use the initializer list

    #include "type1_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    55/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    using namespace std;

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return vector(message, message + sizeof message);}

    #include "type1_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    56/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    using namespace std;

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return vector(message, message + sizeof message);}

    use std::size_t whenappropriate

    #include "type1_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    57/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    using namespace std;

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return vector(message, message + sizeof message);}

    #include "type1_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    58/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    using namespace std;

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return vector(message, message + sizeof message);}

    #include "type1_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    59/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return vector(message, message + sizeof message);}

    #include "type1_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    60/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return vector(message, message + sizeof message);}

    #include "type1_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    61/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    std::vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return vector(message, message + sizeof message);}

    #include "type1_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    62/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    std::vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return vector(message, message + sizeof message);}

    #include "type1_message.hpp"

    #i l d " l h "

  • 8/3/2019 Solid C++ by Examples

    63/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    std::vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return std::vector(message, message + sizeof message);}

    #include "type1_message.hpp"

    #i l d "t l h "

  • 8/3/2019 Solid C++ by Examples

    64/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    std::vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return std::vector(message, message + sizeof message);}

    #include "type1_message.hpp"

    #i l d "t l h "

  • 8/3/2019 Solid C++ by Examples

    65/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    std::vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const int ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return std::vector(message, message + sizeof message);}

  • 8/3/2019 Solid C++ by Examples

    66/204

    #include "type1_message.hpp"

    #include "tools hpp"

  • 8/3/2019 Solid C++ by Examples

    67/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    std::vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const std::size_t ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return std::vector(message, message + sizeof message);}

    #include "type1_message.hpp"

    #include "tools hpp"

  • 8/3/2019 Solid C++ by Examples

    68/204

    #include "tools.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    pal::type1_message::type1_message(uint32_t ssp_flags){

    ssp_flags_ = ssp_flags;}

    std::vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const std::size_t ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return std::vector(message, message + sizeof message);}

    #include "type1_message.hpp"

    #include "tools hpp"

  • 8/3/2019 Solid C++ by Examples

    69/204

    #include tools.hpp

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    pal::type1_message::type1_message(uint32_t ssp_flags): ssp_flags_(ssp_flags)

    {}

    std::vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const std::size_t ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return std::vector(message, message + sizeof message);}

    #include "type1_message.hpp"

    #include "tools hpp"

  • 8/3/2019 Solid C++ by Examples

    70/204

    #include tools.hpp

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    pal::type1_message::type1_message(uint32_t ssp_flags): ssp_flags_(ssp_flags)

    {}

    std::vector pal::type1_message::as_bytes() const{uint8_t message[16] = {

    'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const std::size_t ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);

    return std::vector(message, message + sizeof message);}

    #include "type1_message.hpp"

    #include "tools hpp"

  • 8/3/2019 Solid C++ by Examples

    71/204

    #include tools.hpp

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    pal::type1_message::type1_message(uint32_t ssp_flags): ssp_flags_(ssp_flags)

    {}

    std::vector pal::type1_message::as_bytes() const

    { uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const std::size_t ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);return std::vector(message, message + sizeof message);

    }

    #include "type1_message.hpp"

    #include "tools hpp"

  • 8/3/2019 Solid C++ by Examples

    72/204

    #include tools.hpp

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    pal::type1_message::type1_message(uint32_t ssp_flags): ssp_flags_(ssp_flags)

    {}

    std::vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const std::size_t ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);return std::vector(message, message + sizeof message);

    }

    #include "type1_message.hpp"

    #include "tools hpp"

  • 8/3/2019 Solid C++ by Examples

    73/204

    #include tools.hpp

    /** See http://davenport.sourceforge.net/ntlm.html** Type 1 Message

    ** 0 NTLMSSP Signature "NTLMSSP\0"* 8 NTLM Message Type {0x01,0x00,0x00,0x00}* 12 Flags uint32 as little endian* (16) Supplied Domain (optional) (security buffer)* (24) Supplied Workstation (optional) (security buffer)* (32) (start of datablock) if required*/

    pal::type1_message::type1_message(uint32_t ssp_flags): ssp_flags_(ssp_flags)

    {}

    std::vector pal::type1_message::as_bytes() const{

    uint8_t message[16] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', '\0',0x01, 0x00, 0x00, 0x00, 0, 0, 0, 0

    };const std::size_t ssp_flags_offset = 12;pal::write_little_endian_from_uint32(&message[ssp_flags_offset], ssp_flags_);return std::vector(message, message + sizeof message);

    }

    This is better

  • 8/3/2019 Solid C++ by Examples

    74/204

    type2_message.hpp

  • 8/3/2019 Solid C++ by Examples

    75/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    using namespace std;

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(vector buffer);virtual vector as_bytes() const;uint32_t ssp_flags();

    uint64_t challenge();private:

    const vector buffer_;};

    }

    #endif

    Find 3 issues

  • 8/3/2019 Solid C++ by Examples

    76/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    using namespace std;

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(vector buffer);virtual vector as_bytes() const;uint32_t ssp_flags();

    uint64_t challenge();private:

    const vector buffer_;};

    }

    #endif

    Find 3 issues

  • 8/3/2019 Solid C++ by Examples

    77/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    using namespace std;

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(vector buffer);virtual vector as_bytes() const;uint32_t ssp_flags();

    uint64_t challenge();private:

    const vector buffer_;};

    }

    #endif

    Ouch, do not

  • 8/3/2019 Solid C++ by Examples

    78/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    using namespace std;

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(vector buffer);virtual vector as_bytes() const;uint32_t ssp_flags();

    uint64_t challenge();private:

    const vector buffer_;};

    }

    #endif

    import namespaces inheader files!

  • 8/3/2019 Solid C++ by Examples

    79/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    using namespace std;

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(vector buffer);virtual vector as_bytes() const;uint32_t ssp_flags();

    uint64_t challenge();private:

    const vector buffer_;};

    }

    #endif

    pass this vector as

  • 8/3/2019 Solid C++ by Examples

    80/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    using namespace std;

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(vector buffer);virtual vector as_bytes() const;uint32_t ssp_flags();

    uint64_t challenge();private:

    const vector buffer_;};

    }

    #endif

    pconst &

  • 8/3/2019 Solid C++ by Examples

    81/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    using namespace std;

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(vector buffer);virtual vector as_bytes() const;uint32_t ssp_flags();

    uint64_t challenge();private:

    const vector buffer_;};

    }

    #endif

    this looks like queryth d th h ld

  • 8/3/2019 Solid C++ by Examples

    82/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    using namespace std;

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(vector buffer);virtual vector as_bytes() const;uint32_t ssp_flags();

    uint64_t challenge();private:

    const vector buffer_;};

    }

    #endif

    methods, they shouldprobably be const

  • 8/3/2019 Solid C++ by Examples

    83/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(vector buffer);virtual vector as_bytes() const;uint32_t ssp_flags();

    uint64_t challenge();private:

    const vector buffer_;};

    }

    #endif

    using namespace std;

  • 8/3/2019 Solid C++ by Examples

    84/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(vector buffer);virtual vector as_bytes() const;uint32_t ssp_flags();uint64_t challenge();

    private:

    const vector buffer_;};

    }

    #endif

  • 8/3/2019 Solid C++ by Examples

    85/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(vector buffer);virtual vector as_bytes() const;uint32_t ssp_flags();uint64_t challenge();

    private:

    const vector buffer_;};

    }

    #endif

  • 8/3/2019 Solid C++ by Examples

    86/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message( vector buffer);virtual vector as_bytes() const;uint32_t ssp_flags();uint64_t challenge();

    private:

    const vector buffer_;};

    }

    #endif

  • 8/3/2019 Solid C++ by Examples

    87/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(std::vector buffer);virtual std::vector as_bytes() const;uint32_t ssp_flags();uint64_t challenge();

    private:

    const std::vector buffer_;};

    }

    #endif

  • 8/3/2019 Solid C++ by Examples

    88/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(std::vector buffer);virtual std::vector as_bytes() const;uint32_t ssp_flags();uint64_t challenge();

    private:

    const std::vector buffer_;};

    }

    #endif

  • 8/3/2019 Solid C++ by Examples

    89/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(std::vector buffer);virtual std::vector as_bytes() const;uint32_t ssp_flags();uint64_t challenge();

    private:

    const std::vector buffer_;};

    }

    #endif

  • 8/3/2019 Solid C++ by Examples

    90/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(std::vector buffer);virtual std::vector as_bytes() const;uint32_t ssp_flags();uint64_t challenge();

    private:

    const std::vector buffer_;};

    }

    #endif

  • 8/3/2019 Solid C++ by Examples

    91/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message( std::vector buffer);virtual std::vector as_bytes() const;uint32_t ssp_flags();uint64_t challenge();

    private:

    const std::vector buffer_;};

    }

    #endif

  • 8/3/2019 Solid C++ by Examples

    92/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(conststd::vector & buffer);virtual std::vector as_bytes() const;uint32_t ssp_flags();uint64_t challenge();

    private:

    const std::vector buffer_;};

    }

    #endif

  • 8/3/2019 Solid C++ by Examples

    93/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(const std::vector & buffer);virtual std::vector as_bytes() const;uint32_t ssp_flags();uint64_t challenge();

    private:

    const std::vector buffer_;};

    }

    #endif

  • 8/3/2019 Solid C++ by Examples

    94/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(const std::vector & buffer);virtual std::vector as_bytes() const;uint32_t ssp_flags() const;uint64_t challenge() const;

    private:

    const std::vector buffer_;};

    }

    #endif

  • 8/3/2019 Solid C++ by Examples

    95/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(const std::vector & buffer);virtual std::vector as_bytes() const;uint32_t ssp_flags() const;uint64_t challenge() const;

    private:

    const std::vector buffer_;};

    }

    #endif

    This looks like Solid C++

  • 8/3/2019 Solid C++ by Examples

    96/204

    #ifndef PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #define PAL_TYPE2_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    namespace pal {

    class type2_message : public ntlm_message {public:

    explicit type2_message(const std::vector & buffer);virtual std::vector as_bytes() const;uint32_t ssp_flags() const;uint64_t challenge() const;

    private:

    const std::vector buffer_;};

    }

    #endif

    This looks like Solid C++

  • 8/3/2019 Solid C++ by Examples

    97/204

    type2_message.cpp

    #include

    ... page 1 of 2

  • 8/3/2019 Solid C++ by Examples

    98/204

    #include cstddef#include #include

    #include "tools.hpp"

    #include "type2_message.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 2 Message*

    * 0 NTLMSSP Signature {'N','T','L','M','S','S','P','\0'}* 8 NTLM Message Type {0x02,0x00,0x00,0x00}* 12 Target Name (security buffer)* 20 Flags uint32 as little endian* 24 Challenge 8 bytes / uint64 as little endian* (32) Context (optional) 8 bytes (2xlong)* (40) Target Information (security buffer)* (48) (start of datablock)* targetname* targetinfo* server (type=0x0100, len, data)* domain (type=0x0200, len, data)* dnsserver (type=0x0300, len, data)* dnsdomain (type=0x0400, len, data)* type5 (type=0x0500, len, data) // unknown role* (type=0,len=0)*/

    ...

    #include

    ... page 1 of 2Find one issue

  • 8/3/2019 Solid C++ by Examples

    99/204

    #include #include

    #include "tools.hpp"

    #include "type2_message.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 2 Message*

    * 0 NTLMSSP Signature {'N','T','L','M','S','S','P','\0'}* 8 NTLM Message Type {0x02,0x00,0x00,0x00}* 12 Target Name (security buffer)* 20 Flags uint32 as little endian* 24 Challenge 8 bytes / uint64 as little endian* (32) Context (optional) 8 bytes (2xlong)* (40) Target Information (security buffer)* (48) (start of datablock)* targetname* targetinfo* server (type=0x0100, len, data)* domain (type=0x0200, len, data)* dnsserver (type=0x0300, len, data)* dnsdomain (type=0x0400, len, data)* type5 (type=0x0500, len, data) // unknown role* (type=0,len=0)*/

    ...

    #include

    ... page 1 of 2

  • 8/3/2019 Solid C++ by Examples

    100/204

    #include #include

    #include "tools.hpp"

    #include "type2_message.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 2 Message*

    * 0 NTLMSSP Signature {'N','T','L','M','S','S','P','\0'}* 8 NTLM Message Type {0x02,0x00,0x00,0x00}* 12 Target Name (security buffer)* 20 Flags uint32 as little endian* 24 Challenge 8 bytes / uint64 as little endian* (32) Context (optional) 8 bytes (2xlong)* (40) Target Information (security buffer)* (48) (start of datablock)* targetname* targetinfo* server (type=0x0100, len, data)* domain (type=0x0200, len, data)* dnsserver (type=0x0300, len, data)* dnsdomain (type=0x0400, len, data)* type5 (type=0x0500, len, data) // unknown role* (type=0,len=0)*/

    ...

    #include

    ... page 1 of 2 this is not a good wayt d th i l d fil

  • 8/3/2019 Solid C++ by Examples

    101/204

    #include #include

    #include "tools.hpp"

    #include "type2_message.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 2 Message*

    * 0 NTLMSSP Signature {'N','T','L','M','S','S','P','\0'}* 8 NTLM Message Type {0x02,0x00,0x00,0x00}* 12 Target Name (security buffer)* 20 Flags uint32 as little endian* 24 Challenge 8 bytes / uint64 as little endian* (32) Context (optional) 8 bytes (2xlong)* (40) Target Information (security buffer)* (48) (start of datablock)* targetname* targetinfo* server (type=0x0100, len, data)* domain (type=0x0200, len, data)* dnsserver (type=0x0300, len, data)* dnsdomain (type=0x0400, len, data)* type5 (type=0x0500, len, data) // unknown role* (type=0,len=0)*/

    ...

    to order the include files

    #include

    ... page 1 of 2

  • 8/3/2019 Solid C++ by Examples

    102/204

    #include #include

    #include "tools.hpp"

    #include "type2_message.hpp"

    /** See http://davenport.sourceforge.net/ntlm.html** Type 2 Message*

    * 0 NTLMSSP Signature {'N','T','L','M','S','S','P','\0'}* 8 NTLM Message Type {0x02,0x00,0x00,0x00}* 12 Target Name (security buffer)* 20 Flags uint32 as little endian* 24 Challenge 8 bytes / uint64 as little endian* (32) Context (optional) 8 bytes (2xlong)* (40) Target Information (security buffer)* (48) (start of datablock)* targetname* targetinfo* server (type=0x0100, len, data)* domain (type=0x0200, len, data)* dnsserver (type=0x0300, len, data)* dnsdomain (type=0x0400, len, data)* type5 (type=0x0500, len, data) // unknown role* (type=0,len=0)*/

    ...

    ... page 1 of 2#include

  • 8/3/2019 Solid C++ by Examples

    103/204

    /** See http://davenport.sourceforge.net/ntlm.html** Type 2 Message*

    * 0 NTLMSSP Signature {'N','T','L','M','S','S','P','\0'}* 8 NTLM Message Type {0x02,0x00,0x00,0x00}* 12 Target Name (security buffer)* 20 Flags uint32 as little endian* 24 Challenge 8 bytes / uint64 as little endian* (32) Context (optional) 8 bytes (2xlong)* (40) Target Information (security buffer)* (48) (start of datablock)* targetname* targetinfo* server (type=0x0100, len, data)* domain (type=0x0200, len, data)* dnsserver (type=0x0300, len, data)* dnsdomain (type=0x0400, len, data)* type5 (type=0x0500, len, data) // unknown role* (type=0,len=0)*/

    ...

    #include "type2_message.hpp"

    #include "tools.hpp"

    #include #include

    ... page 1 of 2#include "type2_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    104/204

    /** See http://davenport.sourceforge.net/ntlm.html** Type 2 Message*

    * 0 NTLMSSP Signature {'N','T','L','M','S','S','P','\0'}* 8 NTLM Message Type {0x02,0x00,0x00,0x00}* 12 Target Name (security buffer)* 20 Flags uint32 as little endian* 24 Challenge 8 bytes / uint64 as little endian* (32) Context (optional) 8 bytes (2xlong)* (40) Target Information (security buffer)* (48) (start of datablock)* targetname* targetinfo* server (type=0x0100, len, data)* domain (type=0x0200, len, data)* dnsserver (type=0x0300, len, data)* dnsdomain (type=0x0400, len, data)* type5 (type=0x0500, len, data) // unknown role* (type=0,len=0)*/

    ...

    yp _ g pp

    #include "tools.hpp"

    #include

    #include #include

    pal::type2_message::type2_message(const std::vector & buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    105/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof(prefix), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    return pal::read_uint32_from_little_endian(&buffer_[20]);}

    uint64_t pal::type2_message::challenge() const{

    return pal::read_uint64_from_little_endian(&buffer_[24]);}

    std::vector pal::type2_message::as_bytes() const{

    return (buffer_);}

    pal::type2_message::type2_message(const std::vector & buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    106/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof(prefix), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    return pal::read_uint32_from_little_endian(&buffer_[20]);}

    uint64_t pal::type2_message::challenge() const{

    return pal::read_uint64_from_little_endian(&buffer_[24]);}

    std::vector pal::type2_message::as_bytes() const{

    return (buffer_);}

    Any issues here?

    pal::type2_message::type2_message(const std::vector & buffer)ff ( ff )

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    107/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof(prefix), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    return pal::read_uint32_from_little_endian(&buffer_[20]);}

    uint64_t pal::type2_message::challenge() const{

    return pal::read_uint64_from_little_endian(&buffer_[24]);}

    std::vector pal::type2_message::as_bytes() const{

    return (buffer_);}

    pal::type2_message::type2_message(const std::vector & buffer)b ff (b ff )

    ... page 2 of 2

    magic numbers

  • 8/3/2019 Solid C++ by Examples

    108/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof(prefix), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    return pal::read_uint32_from_little_endian(&buffer_[20]);}

    uint64_t pal::type2_message::challenge() const{

    return pal::read_uint64_from_little_endian(&buffer_[24]);}

    std::vector pal::type2_message::as_bytes() const{

    return (buffer_);}

    pal::type2_message::type2_message(const std::vector & buffer)b ff (b ff )

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    109/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof(prefix), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    return pal::read_uint32_from_little_endian(&buffer_[20]);}

    uint64_t pal::type2_message::challenge() const{

    return pal::read_uint64_from_little_endian(&buffer_[24]);}

    std::vector pal::type2_message::as_bytes() const{

    return (buffer_);}

    pal::type2_message::type2_message(const std::vector & buffer)b ff (b ff )

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    110/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof(prefix), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    return pal::read_uint32_from_little_endian(&buffer_[20]);}

    uint64_t pal::type2_message::challenge() const{

    return pal::read_uint64_from_little_endian(&buffer_[24]);}

    std::vector pal::type2_message::as_bytes() const{

    return (buffer_);}

    superfluous use of ()

    pal::type2_message::type2_message(const std::vector & buffer): buffer (buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    111/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof(prefix), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    return pal::read_uint32_from_little_endian(&buffer_[20]);}

    uint64_t pal::type2_message::challenge() const{

    return pal::read_uint64_from_little_endian(&buffer_[24]);}

    std::vector pal::type2_message::as_bytes() const{

    return (buffer_);}

    superfluous use of ()

    pal::type2_message::type2_message(const std::vector & buffer): buffer (buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    112/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof((prefix)), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    return pal::read_uint32_from_little_endian(&buffer_[20]);}

    uint64_t pal::type2_message::challenge() const{

    return pal::read_uint64_from_little_endian(&buffer_[24]);

    }

    std::vector pal::type2_message::as_bytes() const{

    return (((buffer_)));}

    so you really like () do you?Why not add a few more?

    pal::type2_message::type2_message(const std::vector & buffer): buffer (buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    113/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size =(32);if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof((prefix)), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    return pal::read_uint32_from_little_endian(&buffer_[20]);}

    uint64_t pal::type2_message::challenge() const{

    return pal::read_uint64_from_little_endian(&buffer_[24]);

    }

    std::vector pal::type2_message::as_bytes() const{

    return (((buffer_)));}

    so you really like () do you?Why not add a few more?

    pal::type2_message::type2_message(const std::vector & buffer): buffer (buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    114/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof(prefix), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    return pal::read_uint32_from_little_endian(&buffer_[20]);}

    uint64_t pal::type2_message::challenge() const{

    return pal::read_uint64_from_little_endian(&buffer_[24]);

    }

    std::vector pal::type2_message::as_bytes() const{

    return (buffer_);}

    pal::type2_message::type2_message(const std::vector & buffer): buffer (buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    115/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof(prefix), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    return pal::read_uint32_from_little_endian(&buffer_[20]);}

    uint64_t pal::type2_message::challenge() const{

    return pal::read_uint64_from_little_endian(&buffer_[24]);}

    std::vector pal::type2_message::as_bytes() const{

    return (buffer_);}

    pal::type2_message::type2_message(const std::vector & buffer): buffer (buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    116/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof(prefix), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    return pal::read_uint32_from_little_endian(&buffer_[20]);}

    uint64_t pal::type2_message::challenge() const{

    return pal::read_uint64_from_little_endian(&buffer_[24]);}

    std::vector pal::type2_message::as_bytes() const{

    return (buffer_);}

    pal::type2_message::type2_message(const std::vector & buffer): buffer (buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    117/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof(prefix), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    return pal::read_uint32_from_little_endian(&buffer_[20]);}

    uint64_t pal::type2_message::challenge() const{

    return pal::read_uint64_from_little_endian(&buffer_[24]);}

    std::vector pal::type2_message::as_bytes() const{

    return (buffer_);}

    pal::type2_message::type2_message(const std::vector & buffer): buffer (buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    118/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof(prefix), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    const std::size_t ssp_flags_offset = 20;return pal::read_uint32_from_little_endian(&buffer_[20]);

    }

    uint64_t pal::type2_message::challenge() const{

    const std::size_t challenge_offset = 24;return pal::read_uint64_from_little_endian(&buffer_[24]);

    }

    std::vector pal::type2_message::as_bytes() const{

    return (buffer_);}

    pal::type2_message::type2_message(const std::vector & buffer): buffer (buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    119/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof(prefix), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    const std::size_t ssp_flags_offset = 20;return pal::read_uint32_from_little_endian(&buffer_[20]);

    }

    uint64_t pal::type2_message::challenge() const{

    const std::size_t challenge_offset = 24;return pal::read_uint64_from_little_endian(&buffer_[24]);

    }

    std::vector pal::type2_message::as_bytes() const{

    return (buffer_);}

    pal::type2_message::type2_message(const std::vector & buffer): buffer (buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    120/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof(prefix), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    const std::size_t ssp_flags_offset = 20;return pal::read_uint32_from_little_endian(&buffer_[ssp_flags_offset]);

    }

    uint64_t pal::type2_message::challenge() const{

    const std::size_t challenge_offset = 24;return pal::read_uint64_from_little_endian(&buffer_[24]);

    }

    std::vector pal::type2_message::as_bytes() const{

    return (buffer_);}

    pal::type2_message::type2_message(const std::vector & buffer): buffer (buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    121/204

    : buffer_(buffer){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof(prefix), buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    const std::size_t ssp_flags_offset = 20;return pal::read_uint32_from_little_endian(&buffer_[ssp_flags_offset]);

    }

    uint64_t pal::type2_message::challenge() const{

    const std::size_t challenge_offset = 24;return pal::read_uint64_from_little_endian(&buffer_[challenge_offset]);

    }

    std::vector pal::type2_message::as_bytes() const{

    return (buffer_);}

    pal::type2_message::type2_message(const std::vector & buffer): buffer (buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    122/204

    ( )

    _( ){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof prefix , buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    const std::size_t ssp_flags_offset = 20;return pal::read_uint32_from_little_endian(&buffer_[ssp_flags_offset]);

    }

    uint64_t pal::type2_message::challenge() const{

    const std::size_t challenge_offset = 24;return pal::read_uint64_from_little_endian(&buffer_[challenge_offset]);

    }

    std::vector pal::type2_message::as_bytes() const{

    return buffer_ ;}

    ( )

    pal::type2_message::type2_message(const std::vector & buffer): buffer (buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    123/204

    _( ){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof prefix , buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    const std::size_t ssp_flags_offset = 20;return pal::read_uint32_from_little_endian(&buffer_[ssp_flags_offset]);

    }

    uint64_t pal::type2_message::challenge() const{

    const std::size_t challenge_offset = 24;return pal::read_uint64_from_little_endian(&buffer_[challenge_offset]);

    }

    std::vector pal::type2_message::as_bytes() const{

    return buffer_ ;}

    ( )

    pal::type2_message::type2_message(const std::vector & buffer): buffer (buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    124/204

    _( ){

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof prefix , buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    const std::size_t ssp_flags_offset = 20;return pal::read_uint32_from_little_endian(&buffer_[ssp_flags_offset]);

    }

    uint64_t pal::type2_message::challenge() const{

    const std::size_t challenge_offset = 24;return pal::read_uint64_from_little_endian(&buffer_[challenge_offset]);

    }

    std::vector pal::type2_message::as_bytes() const{

    return buffer_ ;}

    ( )

    pal::type2_message::type2_message(const std::vector & buffer): buffer_(buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    125/204

    _{

    const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {

    'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof prefix , buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    const std::size_t ssp_flags_offset = 20;return pal::read_uint32_from_little_endian(&buffer_[ssp_flags_offset]);

    }

    uint64_t pal::type2_message::challenge() const{

    const std::size_t challenge_offset = 24;return pal::read_uint64_from_little_endian(&buffer_[challenge_offset]);

    }

    std::vector pal::type2_message::as_bytes() const{

    return buffer_ ;}

    pal::type2_message::type2_message(const std::vector & buffer): buffer_(buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    126/204

    {const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {

    'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof prefix, buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    const std::size_t ssp_flags_offset = 20;return pal::read_uint32_from_little_endian(&buffer_[ssp_flags_offset]);

    }

    uint64_t pal::type2_message::challenge() const{

    const std::size_t challenge_offset = 24;return pal::read_uint64_from_little_endian(&buffer_[challenge_offset]);

    }

    std::vector pal::type2_message::as_bytes() const{

    return buffer_;}

    pal::type2_message::type2_message(const std::vector & buffer): buffer_(buffer)

    ... page 2 of 2

  • 8/3/2019 Solid C++ by Examples

    127/204

    {const std::size_t min_type2_buffer_size = 32;if (buffer.size() < min_type2_buffer_size)

    throw std::invalid_argument("not a type2 message, message too short");const uint8_t prefix[12] = {

    'N','T','L','M','S','S','P','\0',0x02,0x00,0x00,0x00

    };if (!std::equal(prefix, prefix + sizeof prefix, buffer.begin()))

    throw std::invalid_argument("not a type2 message, invalid prefix");}

    uint32_t pal::type2_message::ssp_flags() const{

    const std::size_t ssp_flags_offset = 20;return pal::read_uint32_from_little_endian(&buffer_[ssp_flags_offset]);

    }

    uint64_t pal::type2_message::challenge() const{

    const std::size_t challenge_offset = 24;return pal::read_uint64_from_little_endian(&buffer_[challenge_offset]);

    }

    std::vector pal::type2_message::as_bytes() const{

    return buffer_;}

  • 8/3/2019 Solid C++ by Examples

    128/204

    type3_message.hpp

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    129/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    explicit type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,uint32_t ssp_flags = 0x202);

    virtual std::vector as_bytes() const;void debug_print(std::ostream & out) const;

    private:const std::vector lm_response_;const std::vector nt_response_;const std::string domain_;const std::string user_;

    const std::string workstation_;const std::vector session_key_;const uint32_t ssp_flags_;

    };}

    #endif

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    Find 3 issues

  • 8/3/2019 Solid C++ by Examples

    130/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    explicit type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,uint32_t ssp_flags = 0x202);

    virtual std::vector as_bytes() const;void debug_print(std::ostream & out) const;

    private:const std::vector lm_response_;const std::vector nt_response_;const std::string domain_;const std::string user_;

    const std::string workstation_;const std::vector session_key_;const uint32_t ssp_flags_;

    };}

    #endif

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    131/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    explicit type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,uint32_t ssp_flags = 0x202);

    virtual std::vector as_bytes() const;void debug_print(std::ostream & out) const;

    private:const std::vector lm_response_;const std::vector nt_response_;const std::string domain_;const std::string user_;

    const std::string workstation_;const std::vector session_key_;const uint32_t ssp_flags_;

    };}

    #endif

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    include instead

  • 8/3/2019 Solid C++ by Examples

    132/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    explicit type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,uint32_t ssp_flags = 0x202);

    virtual std::vector as_bytes() const;void debug_print(std::ostream & out) const;

    private:const std::vector lm_response_;const std::vector nt_response_;const std::string domain_;const std::string user_;

    const std::string workstation_;const std::vector session_key_;const uint32_t ssp_flags_;

    };}

    #endif

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    133/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    explicit type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,

    uint32_t ssp_flags = 0x202);virtual std::vector as_bytes() const;void debug_print(std::ostream & out) const;

    private:const std::vector lm_response_;const std::vector nt_response_;const std::string domain_;const std::string user_;

    const std::string workstation_;const std::vector session_key_;const uint32_t ssp_flags_;

    };}

    #endif

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    this default argument isprobably not needed

  • 8/3/2019 Solid C++ by Examples

    134/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    explicit type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,

    uint32_t ssp_flags = 0x202);virtual std::vector as_bytes() const;void debug_print(std::ostream & out) const;

    private:const std::vector lm_response_;const std::vector nt_response_;const std::string domain_;const std::string user_;

    const std::string workstation_;const std::vector session_key_;const uint32_t ssp_flags_;

    };}

    #endif

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    135/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    explicit type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,

    uint32_t ssp_flags = 0x202);virtual std::vector as_bytes() const;void debug_print(std::ostream & out) const;

    private:const std::vector lm_response_;const std::vector nt_response_;const std::string domain_;const std::string user_;

    const std::string workstation_;const std::vector session_key_;const uint32_t ssp_flags_;

    };}

    #endif

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

    useless explicit specifier

  • 8/3/2019 Solid C++ by Examples

    136/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    explicit type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,

    uint32_t ssp_flags = 0x202);virtual std::vector as_bytes() const;void debug_print(std::ostream & out) const;

    private:const std::vector lm_response_;const std::vector nt_response_;const std::string domain_;const std::string user_;

    const std::string workstation_;const std::vector session_key_;const uint32_t ssp_flags_;

    };}

    #endif

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    137/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    explicit type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,

    uint32_t ssp_flags = 0x202);virtual std::vector as_bytes() const;void debug_print(std::ostream & out) const;

    private:const std::vector lm_response_;const std::vector nt_response_;const std::string domain_;const std::string user_;

    const std::string workstation_;const std::vector session_key_;const uint32_t ssp_flags_;

    };}

    #endif

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    138/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    explicit type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,

    uint32_t ssp_flags = 0x202);virtual std::vector as_bytes() const;void debug_print(std::ostream & out) const;

    private:const std::vector lm_response_;const std::vector nt_response_;const std::string domain_;const std::string user_;

    const std::string workstation_;const std::vector session_key_;const uint32_t ssp_flags_;

    };}

    #endif

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    139/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    explicit type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,

    uint32_t ssp_flags = 0x202);virtual std::vector as_bytes() const;void debug_print(std::ostream & out) const;

    private:const std::vector lm_response_;const std::vector nt_response_;const std::string domain_;const std::string user_;

    const std::string workstation_;const std::vector session_key_;const uint32_t ssp_flags_;

    };}

    #endif

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    140/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    explicit type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,

    uint32_t ssp_flags = 0x202);virtual std::vector as_bytes() const;void debug_print(std::ostream & out) const;

    private:const std::vector lm_response_;const std::vector nt_response_;const std::string domain_;const std::string user_;

    const std::string workstation_;const std::vector session_key_;const uint32_t ssp_flags_;

    };}

    #endif

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    141/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,

    uint32_t ssp_flags );virtual std::vector as_bytes() const;void debug_print(std::ostream & out) const;

    private:const std::vector lm_response_;const std::vector nt_response_;const std::string domain_;const std::string user_;

    const std::string workstation_;const std::vector session_key_;const uint32_t ssp_flags_;

    };}

    #endif

    = 0x202

    explicit

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    142/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,

    uint32_t ssp_flags );virtual std::vector as_bytes() const;void debug_print(std::ostream & out) const;

    private:const std::vector lm_response_;const std::vector nt_response_;const std::string domain_;const std::string user_;

    const std::string workstation_;const std::vector session_key_;const uint32_t ssp_flags_;

    };}

    #endif

    = 0x202

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    143/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,

    uint32_t ssp_flags );virtual std::vector as_bytes() const;void debug_print(std::ostream & out) const;

    private:const std::vector lm_response_;const std::vector nt_response_;const std::string domain_;const std::string user_;

    const std::string workstation_;const std::vector session_key_;const uint32_t ssp_flags_;

    };}

    #endif

    = 0x202

    #ifndef PAL_TYPE3_MESSAGE_HPP_INCLUDED#define PAL_TYPE3_MESSAGE_HPP_INCLUDED

    #include "ntlm_message.hpp"

  • 8/3/2019 Solid C++ by Examples

    144/204

    #include #include

    namespace pal {

    class type3_message : public ntlm_message {public:

    type3_message(const std::vector & lm_response,const std::vector & nt_response,const std::string & user,

    uint32_t ssp_flags );virtual std::vector as_bytes() const;void debug_print(std::ostream & out)


Recommended