CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
common_SignatureSettingWithKeyBuffer.h
1 /*--------------------------------------------------------------------------------*
2  Copyright (C)Nintendo All rights reserved.
3 
4  These coded instructions, statements, and computer programs contain proprietary
5  information of Nintendo and/or its licensed developers and are protected by
6  national and international copyright laws. They may not be disclosed to third
7  parties or copied or duplicated in any form, in whole or in part, without the
8  prior written consent of Nintendo.
9 
10  The content herein is highly confidential and should be handled accordingly.
11  *--------------------------------------------------------------------------------*/
12 
13 
14 #pragma once
15 
16 #include <nn/pia/common/common_Definitions.h>
17 #include <nn/pia/common/common_SignatureSetting.h>
18 
19 namespace nn
20 {
21 namespace pia
22 {
23 namespace common
24 {
25 
26 
27 /*!
28  @brief 署名鍵のバッファを内部に持つ署名設定情報のクラスです。
29 
30  @param KeySize 鍵のサイズ(バイト数)です。このサイズのバッファが用意されます。
31 
32  */
33 template <uint32_t KeySize>
35 {
36 public:
37  /*!
38  @brief コンストラクタです。署名アルゴリズムを指定して初期化します。
39 
40  @details 鍵データは GetKeyBufferPtr() で得られるアドレスに書き込んでください。
41 
42  @param[in] mode 署名アルゴリズムの種類を指定します。
43  */
45  : SignatureSetting(mode, m_KeyBuffer, KeySize)
46  {
47  ClearKeyBuffer();
48  }
49 
50 
51  /*!
52  @brief コンストラクタです。既定の署名アルゴリズム(HMAC-MD5)で初期化します。
53 
54  @details 鍵データは GetKeyBufferPtr() で得られるアドレスに書き込んでください。
55  */
57  : SignatureSetting(Mode_HmacMd5, m_KeyBuffer, KeySize)
58  {
59  ClearKeyBuffer();
60  }
61 
62 
63  /*!
64  @brief 鍵データバッファへのポインタを取得します。
65 
66  @return 鍵データバッファへのポインタです。
67  */
68  uint8_t* GetKeyBufferPtr()
69  {
70  return m_KeyBuffer;
71  }
72 
73 
74  /*!
75  @brief 署名アルゴリズムを指定します。
76 
77  @param[in] mode 署名アルゴリズムの種類を指定します。
78 
79  @return 正しく設定された場合、成功を表す Result が返されます。
80  @retval ResultInvalidArgument 引数の指定が不正です。プログラミングエラーです。このエラーが返らないようにソースコードを修正してください。
81  */
83  {
84  return Set(mode, m_KeyBuffer, KeySize);
85  }
86 
87 
88  // 鍵データバッファの内容をクリアします。
89  void ClearKeyBuffer()
90  {
91  for (uint32_t i = 0; i < KeySize; ++i)
92  {
93  m_KeyBuffer[i] = 0;
94  }
95  }
96 
97 
98 private:
99  // 使われると m_cpKeyData が m_KeyBuffer を指さなくなるので、外から呼べなくしておきます。
100  // SignatureSetting* としてアクセスしたりすると呼べてしまいますが。
101  Result Set(Mode mode, const void* cpKeyData, uint32_t keySize)
102  {
103  return SignatureSetting::Set(mode, cpKeyData, keySize);
104  }
105 
106 private:
107  uint8_t m_KeyBuffer[KeySize];
108 };
109 }
110 }
111 } // end of namespace nn::pia::common