Win32 API 日本語リファレンス
ホームSecurity.Cryptography › CERT_CONTEXT

CERT_CONTEXT

構造体
サイズx64: 40 バイト / x86: 20 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
dwCertEncodingTypeCERT_QUERY_ENCODING_TYPE4+0+0

使用されるエンコードの種類です。証明書のエンコードの種類とメッセージのエンコードの種類の両方を、次の例のようにビット単位の OR 演算で組み合わせて指定することは常に可能です。

X509_ASN_ENCODING | PKCS_7_ASN_ENCODING 現在定義されているエンコードの種類は次のとおりです。

pbCertEncodedBYTE*8/4+8+4エンコードされた証明書を格納するバッファーへのポインターです。
cbCertEncodedDWORD4+16+8エンコードされた証明書のサイズ (バイト単位) です。
pCertInfoCERT_INFO*8/4+24+12証明書情報を格納する CERT_INFO 構造体のアドレスです。
hCertStoreHCERTSTORE8/4+32+16証明書コンテキストを格納する証明書ストアへのハンドルです。

公式ドキュメント

CERT_CONTEXT 構造体は、証明書のエンコードされた表現とデコードされた表現の両方を格納します。Wincrypt.h で定義されている関数のいずれかによって返された証明書コンテキストは、 CertFreeCertificateContext 関数を呼び出して解放する必要があります。 CertDuplicateCertificateContext 関数を呼び出すと複製を作成できます (複製も CertFreeCertificateContext を呼び出して解放する必要があります)。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での定義

#include <windows.h>

// CERT_CONTEXT  (x64 40 / x86 20 バイト)
typedef struct CERT_CONTEXT {
    CERT_QUERY_ENCODING_TYPE dwCertEncodingType;
    BYTE* pbCertEncoded;
    DWORD cbCertEncoded;
    CERT_INFO* pCertInfo;
    HCERTSTORE hCertStore;
} CERT_CONTEXT;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CERT_CONTEXT
{
    public uint dwCertEncodingType;
    public IntPtr pbCertEncoded;
    public uint cbCertEncoded;
    public IntPtr pCertInfo;
    public IntPtr hCertStore;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure CERT_CONTEXT
    Public dwCertEncodingType As UInteger
    Public pbCertEncoded As IntPtr
    Public cbCertEncoded As UInteger
    Public pCertInfo As IntPtr
    Public hCertStore As IntPtr
End Structure
import ctypes
from ctypes import wintypes

class CERT_CONTEXT(ctypes.Structure):
    _fields_ = [
        ("dwCertEncodingType", wintypes.DWORD),
        ("pbCertEncoded", ctypes.c_void_p),
        ("cbCertEncoded", wintypes.DWORD),
        ("pCertInfo", ctypes.c_void_p),
        ("hCertStore", ctypes.c_void_p),
    ]
#[repr(C)]
pub struct CERT_CONTEXT {
    pub dwCertEncodingType: u32,
    pub pbCertEncoded: *mut core::ffi::c_void,
    pub cbCertEncoded: u32,
    pub pCertInfo: *mut core::ffi::c_void,
    pub hCertStore: *mut core::ffi::c_void,
}
import "golang.org/x/sys/windows"

type CERT_CONTEXT struct {
	dwCertEncodingType uint32
	pbCertEncoded uintptr
	cbCertEncoded uint32
	pCertInfo uintptr
	hCertStore uintptr
}
type
  CERT_CONTEXT = record
    dwCertEncodingType: DWORD;
    pbCertEncoded: Pointer;
    cbCertEncoded: DWORD;
    pCertInfo: Pointer;
    hCertStore: Pointer;
  end;
const CERT_CONTEXT = extern struct {
    dwCertEncodingType: u32,
    pbCertEncoded: ?*anyopaque,
    cbCertEncoded: u32,
    pCertInfo: ?*anyopaque,
    hCertStore: ?*anyopaque,
};
type
  CERT_CONTEXT {.bycopy.} = object
    dwCertEncodingType: uint32
    pbCertEncoded: pointer
    cbCertEncoded: uint32
    pCertInfo: pointer
    hCertStore: pointer
struct CERT_CONTEXT
{
    uint dwCertEncodingType;
    void* pbCertEncoded;
    uint cbCertEncoded;
    void* pCertInfo;
    void* hCertStore;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; CERT_CONTEXT サイズ: 20 バイト(x86)
dim st, 5    ; 4byte整数×5(構造体サイズ 20 / 4 切り上げ)
; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; pbCertEncoded : BYTE* (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; cbCertEncoded : DWORD (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; pCertInfo : CERT_INFO* (+12, 4byte)  varptr(st)+12 を基点に操作(4byte:入れ子/配列)
; hCertStore : HCERTSTORE (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; CERT_CONTEXT サイズ: 40 バイト(x64)
dim st, 10    ; 4byte整数×10(構造体サイズ 40 / 4 切り上げ)
; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; pbCertEncoded : BYTE* (+8, 8byte)  qpoke st,8,値 / qpeek(st,8)  ※IronHSPのみ。3.7/3.8は lpoke st,8,下位 : lpoke st,12,上位
; cbCertEncoded : DWORD (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; pCertInfo : CERT_INFO* (+24, 8byte)  varptr(st)+24 を基点に操作(8byte:入れ子/配列)
; hCertStore : HCERTSTORE (+32, 8byte)  qpoke st,32,値 / qpeek(st,32)  ※IronHSPのみ。3.7/3.8は lpoke st,32,下位 : lpoke st,36,上位
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global CERT_CONTEXT
    #field int dwCertEncodingType
    #field intptr pbCertEncoded
    #field int cbCertEncoded
    #field intptr pCertInfo
    #field intptr hCertStore
#endstruct

stdim st, CERT_CONTEXT        ; NSTRUCT 変数を確保
st->dwCertEncodingType = 100
mes "dwCertEncodingType=" + st->dwCertEncodingType