Merge pull request #5 from intothevoid/master
[KDIS.git] / KDIS / KDIS / DataTypes / CryptoSystem.h
blob25fa65e1bfed08ced6f37fd0b2e4b07900f9b687
1 /*********************************************************************
2 Copyright 2013 Karl Jones
3 All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 For Further Information Please Contact me at
26 Karljj1@yahoo.com
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
30 /********************************************************************
31 class: CryptoSystem
32 created: 2008/10/22
33 author: Karl Jones
35 purpose: Stores details about a transmitters crypto system
36 size: 32 bits / 4 octets
37 *********************************************************************/
39 #pragma once
41 #include "./DataTypeBase.h"
43 namespace KDIS {
44 namespace DATA_TYPE {
46 class KDIS_EXPORT CryptoSystem : public DataTypeBase
48 protected:
50 KUINT16 m_ui16CryptoSystemType;
52 union
54 struct
56 KUINT16 m_ui16KeyID : 15;
57 KUINT16 m_ui16EncryptionMode : 1;
60 KUINT16 m_ui16CryptoKey;
63 public:
65 static const KUINT16 CRYPTO_SYSTEM_SIZE = 4;
67 CryptoSystem();
69 CryptoSystem( KDataStream & stream );
71 CryptoSystem( KDIS::DATA_TYPE::ENUMS::CryptoSystemType CST, KDIS::DATA_TYPE::ENUMS::EncryptionMode EM, KUINT16 Key );
73 virtual ~CryptoSystem();
75 //************************************
76 // FullName: KDIS::DATA_TYPE::CryptoSystem::SetCryptoSystemType
77 // KDIS::DATA_TYPE::CryptoSystem::GetCryptoSystemType
78 // Description: Equipment being used.
79 // Parameter: CryptoSystemType T
80 //************************************
81 void SetCryptoSystemType( KDIS::DATA_TYPE::ENUMS::CryptoSystemType T );
82 KDIS::DATA_TYPE::ENUMS::CryptoSystemType GetCryptoSystemType() const;
84 //************************************
85 // FullName: KDIS::DATA_TYPE::CryptoSystem::SetEncryptionMode
86 // KDIS::DATA_TYPE::CryptoSystem::GetEncryptionMode
87 // Description: Mode being used to encrypt the data.
88 // Parameter: EncryptionMode EM
89 //************************************
90 void SetEncryptionMode( KDIS::DATA_TYPE::ENUMS::EncryptionMode EM );
91 KDIS::DATA_TYPE::ENUMS::EncryptionMode GetEncryptionMode() const;
93 //************************************
94 // FullName: KDIS::DATA_TYPE::CryptoSystem::SetKeyID
95 // KDIS::DATA_TYPE::CryptoSystem::GetKeyID
96 // Description: Mode being used to encrypt the data.
97 // Parameter: EncryptionMode EM
98 //************************************
99 void SetKeyID( KUINT16 KeyID );
100 KUINT16 GetKeyID() const;
102 //************************************
103 // FullName: KDIS::DATA_TYPE::CryptoSystem::SetKey
104 // KDIS::DATA_TYPE::CryptoSystem::GetKey
105 // Description: Key. Not an actual crypto key, if the key
106 // from the sender is the same as the key of the
107 // receiver then they are considered to be using the
108 // same key.
109 // Parameter: KUINT16 EM
110 //************************************
111 void SetKey( KUINT16 K );
112 KUINT16 GetKey() const;
114 //************************************
115 // FullName: KDIS::DATA_TYPE::CryptoSystem::GetAsString
116 // Description: Returns a string representation
117 //************************************
118 virtual KString GetAsString() const;
120 //************************************
121 // FullName: KDIS::DATA_TYPE::CryptoSystem::Decode
122 // Description: Convert From Network Data.
123 // Parameter: KDataStream & stream
124 //************************************
125 virtual void Decode( KDataStream & stream ) ;
127 //************************************
128 // FullName: KDIS::DATA_TYPE::CryptoSystem::Encode
129 // Description: Convert To Network Data.
130 // Parameter: KDataStream & stream
131 //************************************
132 virtual KDataStream Encode() const;
133 virtual void Encode( KDataStream & stream ) const;
135 KBOOL operator == ( const CryptoSystem & Value ) const;
136 KBOOL operator != ( const CryptoSystem & Value ) const;
139 } // END namespace DATA_TYPES
140 } // END namespace KDIS