CTR Pia  4.11.3
Game Communication Engine
common_SignatureSettingWithKeyBuffer.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: common_SignatureSettingWithKeyBuffer.h
4 
5  Copyright Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12  *---------------------------------------------------------------------------*/
13 
14 
15 #pragma once
16 
17 #include <pia/common/common_definitions.h>
18 #include <pia/common/common_SignatureSetting.h>
19 
20 namespace nn
21 {
22 namespace pia
23 {
24 namespace common
25 {
26 
27 
28 /*!
29 @brief This class represents signature setting information and includes an internal signature key buffer.
30 
31 @param KeySize Specifies the key size (in bytes). A buffer of this size is configured.
32 
33 @date 2012-11-30 Initial version.
34 */
35 template <size_t KeySize>
37 {
38 public:
39 /*!
40 @brief Instantiates an object. Initializes the object instance using the specified signature algorithm.
41 
42 @details Write the key to the address retrieved by using the <tt>GetKeyBufferPrt</tt> function.
43 
44 @param[in] mode Specifies the type of signature algorithm.
45 */
47  : SignatureSetting(mode, m_KeyBuffer, KeySize)
48  {
49  ClearKeyBuffer();
50  }
51 
52 
53 /*!
54 @brief Instantiates an object. The instance is initialized using the predefined signature algorithm (HMAC-MD5).
55 
56 @details Write the key to the address retrieved by using the <tt>GetKeyBufferPrt</tt> function.
57 */
59  : SignatureSetting(MODE_HMAC_MD5, m_KeyBuffer, KeySize)
60  {
61  ClearKeyBuffer();
62  }
63 
64 
65 /*!
66 @brief Gets a pointer to the key data buffer.
67 
68 @return Returns a pointer to the key data buffer.
69 */
71  {
72  return m_KeyBuffer;
73  }
74 
75 
76 /*!
77 @brief Sets the signature algorithm.
78 
79 @param[in] mode Specifies the type of signature algorithm.
80 
81 @return Returns a <tt>Result</tt> that indicates success if configured correctly.
82 @retval ResultInvalidArgument Indicates an invalid argument. Programming error. Fix your program so that this error is not returned.
83 */
84  nn::Result SetMode(Mode mode)
85  {
86  return Set(mode, m_KeyBuffer, KeySize);
87  }
88 
89 
90  // Clears the content of the key data buffer.
91  void ClearKeyBuffer()
92  {
93  for(size_t i=0; i<KeySize; ++i)
94  {
95  m_KeyBuffer[i] = 0;
96  }
97  }
98 
99 
100 private:
101  // Because <tt>m_cpKeyData</tt> cannot specify <tt>m_KeyBuffer</tt> after this function is used, we have made sure it cannot be called externally.
102  // However, it can be called incorrectly by accessing it as <tt>SignatureSetting*</tt>.
103  nn::Result Set(Mode mode, const void* cpKeyData, size_t keySize)
104  {
105  return SignatureSetting::Set(mode, cpKeyData, keySize);
106  }
107 
108 private:
109  u8 m_KeyBuffer[KeySize];
110 };
111 }
112 }
113 } // end of namespace nn::pia::common
This class maintains signature setting information.
Definition: common_SignatureSetting.h:33
Definition: assert.h:115
This class represents signature setting information and includes an internal signature key buffer...
Definition: common_SignatureSettingWithKeyBuffer.h:36
Mode
Indicates the type of signature algorithm.
Definition: common_SignatureSetting.h:41
nn::Result Set(Mode mode, const void *cpKeyData, size_t keySize)
Sets signature settings.
nn::Result SetMode(Mode mode)
Sets the signature algorithm.
Definition: common_SignatureSettingWithKeyBuffer.h:84
HMAC-MD5 signature.
Definition: common_SignatureSetting.h:44
SignatureSettingWithKeyBuffer()
Instantiates an object. The instance is initialized using the predefined signature algorithm (HMAC-MD...
Definition: common_SignatureSettingWithKeyBuffer.h:58
SignatureSettingWithKeyBuffer(Mode mode)
Instantiates an object. Initializes the object instance using the specified signature algorithm...
Definition: common_SignatureSettingWithKeyBuffer.h:46
u8 * GetKeyBufferPtr()
Gets a pointer to the key data buffer.
Definition: common_SignatureSettingWithKeyBuffer.h:70