Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ELY-5 bis #10

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
81 changes: 81 additions & 0 deletions src/main/java/org/wildfly/security/password/Arrays2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed 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.wildfly.security.password;

/**
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
*/
final class Arrays2 {

private Arrays2() {
}

public static boolean equals(byte[] a1, int offs1, byte[] a2, int offs2, int len) {
if (offs1 + len > a1.length) return false;
if (offs2 + len > a2.length) return false;
for (int i = 0; i < len; i ++) {
if (a1[i + offs1] != a2[i + offs2]) {
return false;
}
}
return true;
}

public static boolean equals(byte[] a1, int offs, byte[] a2) {
return equals(a1, offs, a2, 0, a2.length);
}

public static boolean equals(char[] a1, int offs1, char[] a2, int offs2, int len) {
if (offs1 + len > a1.length) return false;
if (offs2 + len > a2.length) return false;
for (int i = 0; i < len; i ++) {
if (a1[i + offs1] != a2[i + offs2]) {
return false;
}
}
return true;
}

public static boolean equals(char[] a1, int offs, char[] a2) {
return equals(a1, offs, a2, 0, a2.length);
}

public static boolean equals(char[] a1, int offs1, String a2, int offs2, int len) {
if (offs1 + len > a1.length) return false;
if (offs2 + len > a2.length()) return false;
for (int i = 0; i < len; i ++) {
if (a1[i + offs1] != a2.charAt(i + offs2)) {
return false;
}
}
return true;
}

public static boolean equals(char[] a1, int offs, String a2) {
return equals(a1, offs, a2, 0, a2.length());
}

public static boolean equals(String a1, int offs, char[] a2) {
return equals(a2, 0, a1, offs, a2.length);
}

public static boolean equals(String a1, char[] a2) {
return equals(a1, 0, a2);
}
}