Query an S/MIME entity.
Public Declare Function SMIME_Query Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strFileIn As String, ByVal strQuery As String, ByVal nOptions As Long) As Long
nRet = SMIME_Query(strFileOut, strFileOut, strQuery, nOptions)
long __stdcall SMIME_Query(char *szOutput, long nOutChars, const char *szFileIn, const char *szQuery, long nOptions);
If successful, the return value is a positive number indicating the number of characters (bytes) in the output string, or number of characters required if nOutChars was set to zero. If the item queried cannot be found, the return value is zero. If there is an error (e.g. invalid input), it returns a negative error code.
Public Function smimeQuery
(szFileIn As String, szQuery As String, Optional nOptions As Long = 0) As String
static std::string dipki::Smime::Query (const std::string &inputFile, const std::string &query)
static Smime.query(filename, query)
Valid queries are (case-insensitive):
Query String | Returns |
---|---|
content-type | Value of Content-Type, e.g. "application/pkcs7-mime" |
smime-type | Value of smime-type parameter of Content-Type, e.g. "enveloped-data" |
encoding | Value of Content-Transfer-Encoding, e.g. "base64" |
name | Value of name parameter of Content-Type, e.g. "smime.p7m" |
filename | Value of filename parameter of Content-Disposition, e.g. "smime.p7m" |
If no value is found corresponding to the query then the zero-length empty string ""
is output.
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length. ANSI C users must add one to this value when allocating memory.
Dim strQuery As String Dim strOutput As String Dim nRet As Long Dim strFileIn As String strFileIn = "cmsalice2bob-smime-env.txt" Debug.Print "FILE: " & strFileIn ' Make a buffer large enough to receive output strOutput = String(512, " ") strQuery = "content-type" nRet = SMIME_Query(strOutput, Len(strOutput), strFileIn, strQuery, 0) If nRet <= 0 Then Exit Sub ' catch error Debug.Print strQuery & "=" & Left(strOutput, nRet) strQuery = "smime-type" nRet = SMIME_Query(strOutput, Len(strOutput), strFileIn, strQuery, 0) If nRet <= 0 Then Exit Sub ' catch error Debug.Print strQuery & "=" & Left(strOutput, nRet) strQuery = "encoding" nRet = SMIME_Query(strOutput, Len(strOutput), strFileIn, strQuery, 0) If nRet <= 0 Then Exit Sub ' catch error Debug.Print strQuery & "=" & Left(strOutput, nRet) strQuery = "filename" nRet = SMIME_Query(strOutput, Len(strOutput), strFileIn, strQuery, 0) If nRet <= 0 Then Exit Sub ' catch error Debug.Print strQuery & "=" & Left(strOutput, nRet)
FILE: cmsalice2bob-smime-env.txt content-type=application/pkcs7-mime smime-type=enveloped-data encoding=base64 filename=smime.p7m
Dim strFileIn As String Dim strQuery As String strFileIn = "cmsalice2bob-smime-env.txt" Debug.Print "FILE: " & strFileIn strQuery = "content-type" Debug.Print strQuery & "=" & smimeQuery(strFileIn, strQuery, 0) strQuery = "smime-type" Debug.Print strQuery & "=" & smimeQuery(strFileIn, strQuery, 0) strQuery = "encoding" Debug.Print strQuery & "=" & smimeQuery(strFileIn, strQuery, 0) strQuery = "filename" Debug.Print strQuery & "=" & smimeQuery(strFileIn, strQuery, 0)