bdemers commented on a change in pull request #273: URL: https://github.com/apache/shiro/pull/273#discussion_r554024642
########## File path: crypto/support/hashes/bcrypt/src/main/java/org/apache/shiro/crypto/support/hashes/bcrypt/OpenBSDBase64.java ########## @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.shiro.crypto.support.hashes.bcrypt; + + +/** + * Encoder for the custom Base64 variant of BCrypt (called Radix64 here). It has the same rules as Base64 but uses a + * different mapping table than the various RFCs + * <p> + * According to Wikipedia: + * + * <blockquote> + * Unix stores password hashes computed with crypt in the /etc/passwd file using radix-64 encoding called B64. It uses a + * mostly-alphanumeric set of characters, plus . and /. Its 64-character set is "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz". + * Padding is not used. + * </blockquote> + */ +public interface OpenBSDBase64 { + + + /** + * Encode given raw byte array to a Radix64 style, UTF-8 encoded byte array. + * + * @param rawBytes to encode + * @return UTF-8 encoded string representing radix64 encoded data + */ + byte[] encode(byte[] rawBytes); + + /** + * From a UTF-8 encoded string representing radix64 encoded data as byte array, decodes the raw bytes from it. + * + * @param utf8EncodedRadix64String from a string get it with <code>"m0CrhHm10qJ3lXRY.5zDGO".getBytes(StandardCharsets.UTF8)</code> + * @return the raw bytes encoded by this utf-8 radix4 string + */ + byte[] decode(byte[] utf8EncodedRadix64String); + + /* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + /** + * A mod of Square's Okio Base64 encoder + * <p> + * Original author: Alexander Y. Kleymenov Review comment: ~~If not already make sure this gets added to the NOTICE for this module~~ never minde, i just needed to keep scrolling ########## File path: crypto/support/hashes/bcrypt/src/main/java/org/apache/shiro/crypto/support/hashes/bcrypt/OpenBSDBase64.java ########## @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.shiro.crypto.support.hashes.bcrypt; + + +/** + * Encoder for the custom Base64 variant of BCrypt (called Radix64 here). It has the same rules as Base64 but uses a + * different mapping table than the various RFCs + * <p> + * According to Wikipedia: + * + * <blockquote> + * Unix stores password hashes computed with crypt in the /etc/passwd file using radix-64 encoding called B64. It uses a + * mostly-alphanumeric set of characters, plus . and /. Its 64-character set is "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz". + * Padding is not used. + * </blockquote> + */ +public interface OpenBSDBase64 { + + + /** + * Encode given raw byte array to a Radix64 style, UTF-8 encoded byte array. + * + * @param rawBytes to encode + * @return UTF-8 encoded string representing radix64 encoded data + */ + byte[] encode(byte[] rawBytes); + + /** + * From a UTF-8 encoded string representing radix64 encoded data as byte array, decodes the raw bytes from it. + * + * @param utf8EncodedRadix64String from a string get it with <code>"m0CrhHm10qJ3lXRY.5zDGO".getBytes(StandardCharsets.UTF8)</code> + * @return the raw bytes encoded by this utf-8 radix4 string + */ + byte[] decode(byte[] utf8EncodedRadix64String); + + /* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + /** + * A mod of Square's Okio Base64 encoder + * <p> + * Original author: Alexander Y. Kleymenov Review comment: ~~If not already make sure this gets added to the NOTICE for this module~~ never mind, i just needed to keep scrolling ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
