Skip to content
代码片段 群组 项目
提交 cb4c5bdd 编辑于 作者: Darby Frey's avatar Darby Frey
浏览文件

Better exception handling

上级 a6433b0f
No related branches found
No related tags found
无相关合并请求
...@@ -14,24 +14,21 @@ def initialize(filedata) ...@@ -14,24 +14,21 @@ def initialize(filedata)
end end
def decoded_plist def decoded_plist
@decoded_plist ||= begin p7 = OpenSSL::PKCS7.new(@filedata)
p7 = OpenSSL::PKCS7.new(@filedata) p7.verify(nil, OpenSSL::X509::Store.new, nil, OpenSSL::PKCS7::NOVERIFY)
p7.verify(nil, OpenSSL::X509::Store.new, nil, OpenSSL::PKCS7::NOVERIFY) p7.data
p7.data rescue ArgumentError, OpenSSL::PKCS7::PKCS7Error => err
rescue StandardError => err @error = err.to_s
@error = err.to_s nil
nil
end
end end
strong_memoize_attr :decoded_plist strong_memoize_attr :decoded_plist
def properties def properties
@properties ||= begin list = CFPropertyList::List.new(data: decoded_plist).value
list = CFPropertyList::List.new(data: decoded_plist).value CFPropertyList.native_types(list)
CFPropertyList.native_types(list) rescue CFFormatError, CFPlistError, CFTypeError => err
rescue CFFormatError @error = err.to_s
nil nil
end
end end
strong_memoize_attr :properties strong_memoize_attr :properties
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
it 'returns nil if the property list fails to be parsed from the decoded plist' do it 'returns nil if the property list fails to be parsed from the decoded plist' do
allow(subject).to receive(:decoded_plist).and_return('foo/bar') allow(subject).to receive(:decoded_plist).and_return('foo/bar')
expect(subject.properties).to be nil expect(subject.properties).to be nil
expect(subject.error).to eq('content after root object')
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册