Added CRL issuer (move from x.509 to x509 folder and restructure)
[platform/upstream/iotivity.git] / cloud / account / src / main / java / org / iotivity / cloud / accountserver / x509 / crl / CrlStore.java
1 /*
2  * //******************************************************************
3  * //
4  * // Copyright 2016 Samsung Electronics All Rights Reserved.
5  * //
6  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  * //
8  * // Licensed under the Apache License, Version 2.0 (the "License");
9  * // you may not use this file except in compliance with the License.
10  * // You may obtain a copy of the License at
11  * //
12  * //      http://www.apache.org/licenses/LICENSE-2.0
13  * //
14  * // Unless required by applicable law or agreed to in writing, software
15  * // distributed under the License is distributed on an "AS IS" BASIS,
16  * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * // See the License for the specific language governing permissions and
18  * // limitations under the License.
19  * //
20  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22 package org.iotivity.cloud.accountserver.x509.crl;
23
24 import java.io.FileInputStream;
25 import java.io.FileOutputStream;
26 import java.io.InputStream;
27
28 public final class CrlStore {
29
30     private CrlStore() {
31         throw new AssertionError(); // to get rid of security issue, connected
32                                     // with Java Reflection API
33     }
34
35     private static final String CRL_FILE_NAME = "crl";
36
37     public static void saveCrl(byte[] crl) {
38         try {
39             FileOutputStream out = new FileOutputStream(CRL_FILE_NAME);
40             out.write(crl);
41             out.close();
42         } catch (java.io.IOException e) {
43             e.printStackTrace();
44         }
45     }
46
47     public static byte[] loadCrl() {
48
49         try {
50             InputStream f = new FileInputStream(CRL_FILE_NAME);
51             int size = f.available();
52             byte data[] = new byte[size];
53
54             if(f.read(data) != data.length) {
55                 System.err.println("couldn't read crl");
56             }
57             f.close();
58             return data;
59
60         } catch (java.io.IOException e) {
61             e.printStackTrace();
62         }
63
64         return null;
65     }
66 }