Replace ecomp references
[portal.git] / ecomp-portal-FE-common / client / app / services / base64 / base64.service.js
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38 /**
39  * Author: Rui Lu
40  * 12/15/2016
41  */
42 (function () {
43     class Base64Service {
44          constructor(){
45                 
46          }
47          encode(input) {
48                  var keyStr = 'ABCDEFGHIJKLMNOP' +
49              'QRSTUVWXYZabcdef' +
50              'ghijklmnopqrstuv' +
51              'wxyz0123456789+/' +
52              '=';
53                  var output = "";
54              var chr1, chr2, chr3 = "";
55              var enc1, enc2, enc3, enc4 = "";
56              var i = 0;
57
58              do {
59                  chr1 = input.charCodeAt(i++);
60                  chr2 = input.charCodeAt(i++);
61                  chr3 = input.charCodeAt(i++);
62
63                  enc1 = chr1 >> 2;
64                  enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
65                  enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
66                  enc4 = chr3 & 63;
67
68                  if (isNaN(chr2)) {
69                      enc3 = enc4 = 64;
70                  } else if (isNaN(chr3)) {
71                      enc4 = 64;
72                  }
73
74                  output = output +
75                          keyStr.charAt(enc1) +
76                          keyStr.charAt(enc2) +
77                          keyStr.charAt(enc3) +
78                          keyStr.charAt(enc4);
79                  chr1 = chr2 = chr3 = "";
80                  enc1 = enc2 = enc3 = enc4 = "";
81              } while (i < input.length);
82
83              return output;
84          }
85     }
86     angular.module('ecompApp').service('base64Service', Base64Service)
87 })();