Index: MessageDigestTest.java =================================================================== --- MessageDigestTest.java (revision 0) +++ MessageDigestTest.java (revision 0) @@ -0,0 +1,47 @@ +/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable + * + * 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 tests.api.java.security; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class MessageDigestTest extends junit.framework.TestCase { + + public void testUpdateInvalid() throws NoSuchAlgorithmException { + // Regression test HARMONY-1120 + + // len < 0 + MessageDigest.getInstance("SHA").update(new byte[] {2,2}, 0, -100); + + try { + // offset + len > input.length + MessageDigest.getInstance("SHA").update(new byte[] {2,2}, 0, 5); + fail("Expected IAE"); + } catch (IllegalArgumentException e) { + // expected + } + + try { + // offset < 0 + MessageDigest.getInstance("SHA").update(new byte[] {2,2}, -100, 57); + fail("Expected ArrayIndexOutOfBoundsException"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + + } + +} \ No newline at end of file