WinCommon 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/win_common/crypt/structs.rb +85 -0
- data/lib/win_common/errors/hresult.rb +26 -6
- data/lib/win_common/structs.rb +35 -16
- data/lib/win_common/typedefs.rb +2 -0
- data/lib/win_common/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00ebfa266d5c8e6f2605affc423e17dc86dba69f
|
4
|
+
data.tar.gz: 3349af84a6b33f23281e0fc6b0441451a1f279a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 327c266e6cd9c88e4f16e697ac74ad78f7cfa7b877c474861aa8ef662a60923f5cc576718f080f4e81aca55d01d6a65e4f4eafea04e30a6c260ec7f484582632
|
7
|
+
data.tar.gz: 489b7a6cd44d54144e7aca36fd45817c841cbe66683aa4ed3d078ce36f7edad02f96425915c842453ff1a0075bb6069ba39f53c5a090a914d64c005ea4ebec08
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module WinCommon
|
2
|
+
module Crypt
|
3
|
+
module Structs
|
4
|
+
class CRYPT_INTEGER_BLOB < FFI::Struct
|
5
|
+
layout({
|
6
|
+
:cbData => :DWORD,
|
7
|
+
:pbData => :PBYTE
|
8
|
+
})
|
9
|
+
end
|
10
|
+
|
11
|
+
CRYPT_OBJID_BLOB = CRYPT_INTEGER_BLOB
|
12
|
+
CERT_NAME_BLOB = CRYPT_INTEGER_BLOB
|
13
|
+
|
14
|
+
class CRYPT_ALGORITHM_IDENTIFIER < FFI::Struct
|
15
|
+
layout({
|
16
|
+
:pszObjId => :LPSTR,
|
17
|
+
:Parameters => CRYPT_OBJID_BLOB
|
18
|
+
})
|
19
|
+
end
|
20
|
+
|
21
|
+
class CRYPT_BIT_BLOB < FFI::Struct
|
22
|
+
layout({
|
23
|
+
:cbData => :DWORD,
|
24
|
+
:pbData => :PBYTE,
|
25
|
+
:cUnusedBits => :DWORD
|
26
|
+
})
|
27
|
+
end
|
28
|
+
|
29
|
+
class CERT_PUBLIC_KEY_INFO < FFI::Struct
|
30
|
+
layout({
|
31
|
+
:Algorithm => CRYPT_ALGORITHM_IDENTIFIER,
|
32
|
+
:PublicKey => CRYPT_BIT_BLOB
|
33
|
+
})
|
34
|
+
end
|
35
|
+
|
36
|
+
class CERT_EXTENSION < FFI::Struct
|
37
|
+
layout({
|
38
|
+
:pszObjId => :LPSTR,
|
39
|
+
:fCritical => :BOOL,
|
40
|
+
:Value => CRYPT_OBJID_BLOB
|
41
|
+
})
|
42
|
+
end
|
43
|
+
FFI.typedef CERT_EXTENSION.ptr, :PCERT_EXTENSION
|
44
|
+
|
45
|
+
class CERT_INFO < FFI::Struct
|
46
|
+
layout({
|
47
|
+
:dwVersion => :DWORD,
|
48
|
+
:SerialNumber => CRYPT_INTEGER_BLOB,
|
49
|
+
:SignatureAlgorithm => CRYPT_ALGORITHM_IDENTIFIER,
|
50
|
+
:Issuer => CERT_NAME_BLOB,
|
51
|
+
:NotBefore => WinCommon::Structs::FILETIME,
|
52
|
+
:NotAfter => WinCommon::Structs::FILETIME,
|
53
|
+
:Subject => CERT_NAME_BLOB,
|
54
|
+
:SubjectPublicKeyInfo => CERT_PUBLIC_KEY_INFO,
|
55
|
+
:IssuerUniqueId => CRYPT_BIT_BLOB,
|
56
|
+
:SubjectUniqueId => CRYPT_BIT_BLOB,
|
57
|
+
:cExtension => :DWORD,
|
58
|
+
:rgExtension => :PCERT_EXTENSION
|
59
|
+
})
|
60
|
+
end
|
61
|
+
|
62
|
+
class CERT_CONTEXT < FFI::Struct
|
63
|
+
layout({
|
64
|
+
:dwCertEncodingType => :DWORD,
|
65
|
+
:pbCertEncoded => :PBYTE,
|
66
|
+
:cbCertEncoded => :DWORD,
|
67
|
+
:pCertInfo => CERT_INFO.ptr,
|
68
|
+
:hCertStore => :HCERTSTORE
|
69
|
+
})
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
module Typedefs
|
75
|
+
FFI.typedef Structs::CRYPT_INTEGER_BLOB.ptr, :PCRYPT_INTEGER_BLOB
|
76
|
+
FFI.typedef Structs::CRYPT_OBJID_BLOB.ptr, :PCRYPT_OBJID_BLOB
|
77
|
+
FFI.typedef Structs::CERT_NAME_BLOB.ptr, :PCERT_NAME_BLOB
|
78
|
+
FFI.typedef Structs::CRYPT_ALGORITHM_IDENTIFIER.ptr, :PCRYPT_ALGORITHM_IDENTIFIER
|
79
|
+
FFI.typedef Structs::CRYPT_BIT_BLOB.ptr, :PCRYPT_BIT_BLOB
|
80
|
+
FFI.typedef Structs::CERT_PUBLIC_KEY_INFO.ptr, :PCERT_PUBLIC_KEY_INFO
|
81
|
+
FFI.typedef Structs::CERT_INFO.ptr, :PCERT_INFO
|
82
|
+
FFI.typedef Structs::CERT_CONTEXT.ptr, :PCERT_CONTEXT
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -2,9 +2,6 @@ module WinCommon
|
|
2
2
|
module Errors
|
3
3
|
module HRESULT
|
4
4
|
# Defined in winerror.h
|
5
|
-
SEVERITY_SUCCESS = 0
|
6
|
-
SEVERITY_ERROR = 1
|
7
|
-
NOERROR = 0x00000000
|
8
5
|
S_OK = 0x00000000
|
9
6
|
S_FALSE = 0x00000001
|
10
7
|
E_PENDING = 0x8000000A
|
@@ -41,11 +38,29 @@ module WinCommon
|
|
41
38
|
E_INVALID_DATA = 0x8007000D
|
42
39
|
E_OUTOFMEMORY = 0x8007000E
|
43
40
|
E_INVALIDARG = 0x80070057
|
41
|
+
module SEVERITY
|
42
|
+
SUCCESS = 0
|
43
|
+
ERROR = 1
|
44
|
+
end
|
45
|
+
|
44
46
|
def self.toUnsigned(hresult)
|
45
47
|
hresult += 0x1_0000_0000 if (hresult < 0)
|
46
48
|
hresult
|
47
49
|
end
|
48
50
|
|
51
|
+
def self.Compare(error, code)
|
52
|
+
error = toUnsigned(error)
|
53
|
+
error <=> code
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.Equal?(error, codes)
|
57
|
+
[*codes].include?(toUnsigned(error))
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.ErrorIfEqual(error, code)
|
61
|
+
raise HRESULTError.new(error) if Equal?(error, code)
|
62
|
+
end
|
63
|
+
|
49
64
|
def self.GetSeverity(hresult)
|
50
65
|
(toUnsigned(hresult) >> 31) & 0x01
|
51
66
|
end
|
@@ -59,11 +74,11 @@ module WinCommon
|
|
59
74
|
end
|
60
75
|
|
61
76
|
def self.IsSuccess?(hresult)
|
62
|
-
GetSeverity(hresult) ==
|
77
|
+
GetSeverity(hresult) == SEVERITY::SUCCESS
|
63
78
|
end
|
64
79
|
|
65
80
|
def self.IsError?(hresult)
|
66
|
-
GetSeverity(hresult) ==
|
81
|
+
GetSeverity(hresult) == SEVERITY::ERROR
|
67
82
|
end
|
68
83
|
|
69
84
|
def self.GetName(hresult)
|
@@ -79,13 +94,18 @@ module WinCommon
|
|
79
94
|
'UKNOWN_ERROR'
|
80
95
|
end
|
81
96
|
end
|
97
|
+
|
98
|
+
def self.GetNameCode(hresult)
|
99
|
+
code = HRESULT.toUnsigned(hresult)
|
100
|
+
HRESULT.GetName(code) + " [0x%08X]" % code
|
101
|
+
end
|
82
102
|
end
|
83
103
|
|
84
104
|
class HRESULTError < WinCommonError
|
85
105
|
attr_reader :code
|
86
106
|
def initialize(hr)
|
87
107
|
@code = HRESULT.toUnsigned(hr)
|
88
|
-
super(HRESULT.
|
108
|
+
super(HRESULT.GetNameCode(@code))
|
89
109
|
end
|
90
110
|
end
|
91
111
|
end
|
data/lib/win_common/structs.rb
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
module WinCommon
|
2
2
|
module Structs
|
3
|
+
class POINT < FFI::Struct
|
4
|
+
layout({
|
5
|
+
:x => :LONG,
|
6
|
+
:y => :LONG
|
7
|
+
})
|
8
|
+
end
|
9
|
+
|
10
|
+
class SIZE < FFI::Struct
|
11
|
+
layout({
|
12
|
+
:cx => :LONG,
|
13
|
+
:cy => :LONG
|
14
|
+
})
|
15
|
+
end
|
16
|
+
|
17
|
+
class FILETIME < FFI::Struct
|
18
|
+
layout({
|
19
|
+
:dwLowDateTime => :DWORD,
|
20
|
+
:dwHighDateTime => :DWORD
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
3
24
|
class GUID < FFI::Struct
|
4
25
|
layout({
|
5
26
|
:data1 => :ulong,
|
@@ -31,14 +52,9 @@ module WinCommon
|
|
31
52
|
end
|
32
53
|
end
|
33
54
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
class CLSID < GUID
|
38
|
-
end
|
39
|
-
|
40
|
-
class FMTID < GUID
|
41
|
-
end
|
55
|
+
IID = GUID
|
56
|
+
CLSID = GUID
|
57
|
+
FMTID = GUID
|
42
58
|
|
43
59
|
class WideString
|
44
60
|
extend FFI::DataConverter
|
@@ -60,13 +76,16 @@ module WinCommon
|
|
60
76
|
end
|
61
77
|
|
62
78
|
module Typedefs
|
63
|
-
FFI.typedef Structs::
|
64
|
-
FFI.typedef Structs::
|
65
|
-
FFI.typedef Structs::
|
66
|
-
FFI.typedef Structs::
|
67
|
-
FFI.typedef Structs::
|
68
|
-
FFI.typedef Structs::
|
69
|
-
FFI.typedef Structs::
|
70
|
-
FFI.typedef Structs::
|
79
|
+
FFI.typedef Structs::POINT.ptr, :PPOINT
|
80
|
+
FFI.typedef Structs::SIZE.ptr, :PSIZE
|
81
|
+
FFI.typedef Structs::FILETIME.ptr, :PFILETIME
|
82
|
+
FFI.typedef Structs::GUID.ptr, :LPGUID
|
83
|
+
FFI.typedef Structs::GUID.ptr, :LPCGUID
|
84
|
+
FFI.typedef Structs::IID.ptr, :LPIID
|
85
|
+
FFI.typedef Structs::CLSID.ptr, :LPCLSID
|
86
|
+
FFI.typedef Structs::FMTID.ptr, :LPFMTID
|
87
|
+
FFI.typedef Structs::GUID.by_ref(:in), :REFGUID
|
88
|
+
FFI.typedef Structs::IID.by_ref(:in), :REFIID
|
89
|
+
FFI.typedef Structs::CLSID.by_ref(:in), :REFCLSID
|
71
90
|
end
|
72
91
|
end
|
data/lib/win_common/typedefs.rb
CHANGED
@@ -45,6 +45,7 @@ module WinCommon
|
|
45
45
|
FFI.typedef :WORD, :FSHORT
|
46
46
|
FFI.typedef :DWORD, :FLONG
|
47
47
|
FFI.typedef :LONG, :HRESULT
|
48
|
+
FFI.typedef :pointer, :PHRESULT
|
48
49
|
FFI.typedef :char, :CCHAR
|
49
50
|
FFI.typedef :DWORD, :LCID
|
50
51
|
FFI.typedef :PDWORD, :PLCID
|
@@ -116,6 +117,7 @@ module WinCommon
|
|
116
117
|
FFI.typedef :HANDLE, :HICON
|
117
118
|
FFI.typedef :HANDLE, :HMENU
|
118
119
|
FFI.typedef :HICON, :HCURSOR
|
120
|
+
FFI.typedef :HANDLE, :HCERTSTORE
|
119
121
|
FFI.typedef :short, :WCHAR
|
120
122
|
FFI.typedef :pointer, :PWCHAR
|
121
123
|
FFI.typedef :pointer, :LPWCH
|
data/lib/win_common/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: WinCommon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dāvis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- UNLICENSE
|
56
56
|
- lib/win_common.rb
|
57
57
|
- lib/win_common/constants.rb
|
58
|
+
- lib/win_common/crypt/structs.rb
|
58
59
|
- lib/win_common/enums.rb
|
59
60
|
- lib/win_common/errors.rb
|
60
61
|
- lib/win_common/errors/hresult.rb
|