Java Examples for java.security.InvalidParameterException

The following java examples will help you to understand the usage of java.security.InvalidParameterException. These source code samples are taken from different open source projects.

Example 1
Project: Yhb-2.0-master  File: NumberUtils.java View source code
public static float[][] getControlPointsFor(int start) {
    switch(start) {
        case (-1):
            return Null.getInstance().getControlPoints();
        case 0:
            return Zero.getInstance().getControlPoints();
        case 1:
            return One.getInstance().getControlPoints();
        case 2:
            return Two.getInstance().getControlPoints();
        case 3:
            return Three.getInstance().getControlPoints();
        case 4:
            return Four.getInstance().getControlPoints();
        case 5:
            return Five.getInstance().getControlPoints();
        case 6:
            return Six.getInstance().getControlPoints();
        case 7:
            return Seven.getInstance().getControlPoints();
        case 8:
            return Eight.getInstance().getControlPoints();
        case 9:
            return Nine.getInstance().getControlPoints();
        default:
            throw new InvalidParameterException("Unsupported number requested");
    }
}
Example 2
Project: openjdk-master  File: TestDSAGenParameterSpec.java View source code
private static void testDSAGenParameterSpec(DataTuple dataTuple) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidParameterSpecException, InvalidAlgorithmParameterException {
    System.out.printf("Test case: primePLen=%d, " + "subprimeQLen=%d%n", dataTuple.primePLen, dataTuple.subprimeQLen);
    AlgorithmParameterGenerator apg = AlgorithmParameterGenerator.getInstance(ALGORITHM_NAME, PROVIDER_NAME);
    DSAGenParameterSpec genParamSpec = createGenParameterSpec(dataTuple);
    // genParamSpec will be null if IllegalAE is thrown when expected.
    if (genParamSpec == null) {
        return;
    }
    try {
        apg.init(genParamSpec, null);
        AlgorithmParameters param = apg.generateParameters();
        checkParam(param, genParamSpec);
        System.out.println("Test case passed");
    } catch (InvalidParameterException ipe) {
        throw new RuntimeException("Test case failed.", ipe);
    }
}
Example 3
Project: sslcertx-master  File: DecompressInputStream.java View source code
@Override
public int read(byte[] bytes, int off, int len) throws IOException {
    if (len == 0 || off < 0 || bytes == null)
        throw new InvalidParameterException();
    if (remainingBytes == 0) {
        nextPacket();
    }
    int ret;
    int bytesToRead = Math.min(remainingBytes, len);
    if (doDecompress) {
        ret = decompressedByteStream.read(bytes, off, bytesToRead);
    } else {
        ret = baseStream.read(bytes, off, bytesToRead);
    }
    if (ret <= 0) {
        throw new EOFException("got " + ret + "bytes, bytesToRead = " + bytesToRead);
    }
    remainingBytes -= ret;
    return ret;
}
Example 4
Project: android_platform_libcore-master  File: SignatureSpiTest.java View source code
public void testEngineGetParameters() {
    // or rather test that no UnsupportedOperationException is thrown?
    @SuppressWarnings("unused") Signature s = new Signature("dummy") {

        protected AlgorithmParameters engineGetParameters() {
            engineGetParametersCalled = true;
            try {
                super.engineGetParameters();
            } catch (UnsupportedOperationException e) {
                engineGetParametersExceptionOcurred = true;
            }
            return null;
        }

        @Override
        protected Object engineGetParameter(String param) throws InvalidParameterException {
            return null;
        }

        @Override
        protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
        }

        @Override
        protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
        }

        @Override
        protected void engineSetParameter(String param, Object value) throws InvalidParameterException {
        }

        @Override
        protected byte[] engineSign() throws SignatureException {
            return null;
        }

        @Override
        protected void engineUpdate(byte b) throws SignatureException {
        }

        @Override
        protected void engineUpdate(byte[] b, int off, int len) throws SignatureException {
        }

        @Override
        protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
            return false;
        }
    };
    // must call engineGetParameters
    s.getParameters();
    assertTrue(engineGetParametersCalled);
    assertTrue(engineGetParametersExceptionOcurred);
}
Example 5
Project: android-15-master  File: SignatureSpiTest.java View source code
public void testEngineGetParameters() {
    // or rather test that no UnsupportedOperationException is thrown?
    @SuppressWarnings("unused") Signature s = new Signature("dummy") {

        protected AlgorithmParameters engineGetParameters() {
            engineGetParametersCalled = true;
            try {
                super.engineGetParameters();
            } catch (UnsupportedOperationException e) {
                engineGetParametersExceptionOcurred = true;
            }
            return null;
        }

        @Override
        protected Object engineGetParameter(String param) throws InvalidParameterException {
            return null;
        }

        @Override
        protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
        }

        @Override
        protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
        }

        @Override
        protected void engineSetParameter(String param, Object value) throws InvalidParameterException {
        }

        @Override
        protected byte[] engineSign() throws SignatureException {
            return null;
        }

        @Override
        protected void engineUpdate(byte b) throws SignatureException {
        }

        @Override
        protected void engineUpdate(byte[] b, int off, int len) throws SignatureException {
        }

        @Override
        protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
            return false;
        }
    };
    // must call engineGetParameters
    s.getParameters();
    assertTrue(engineGetParametersCalled);
    assertTrue(engineGetParametersExceptionOcurred);
}
Example 6
Project: android-libcore64-master  File: SignatureSpiTest.java View source code
public void testEngineGetParameters() {
    // or rather test that no UnsupportedOperationException is thrown?
    @SuppressWarnings("unused") Signature s = new Signature("dummy") {

        protected AlgorithmParameters engineGetParameters() {
            engineGetParametersCalled = true;
            try {
                super.engineGetParameters();
            } catch (UnsupportedOperationException e) {
                engineGetParametersExceptionOcurred = true;
            }
            return null;
        }

        @Override
        protected Object engineGetParameter(String param) throws InvalidParameterException {
            return null;
        }

        @Override
        protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
        }

        @Override
        protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
        }

        @Override
        protected void engineSetParameter(String param, Object value) throws InvalidParameterException {
        }

        @Override
        protected byte[] engineSign() throws SignatureException {
            return null;
        }

        @Override
        protected void engineUpdate(byte b) throws SignatureException {
        }

        @Override
        protected void engineUpdate(byte[] b, int off, int len) throws SignatureException {
        }

        @Override
        protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
            return false;
        }
    };
    // must call engineGetParameters
    s.getParameters();
    assertTrue(engineGetParametersCalled);
    assertTrue(engineGetParametersExceptionOcurred);
}
Example 7
Project: cm4mm-updater-master  File: StartupReceiver.java View source code
public static void scheduleUpdateService(Context ctx, int updateFrequency) {
    if (updateFrequency < 0)
        throw new InvalidParameterException("updateFrequency can't be negative");
    Preferences prefs = new Preferences(ctx);
    if (showDebugOutput)
        Log.d(TAG, "Scheduling alarm to go off every " + updateFrequency + " msegs");
    Intent i = new Intent(ctx, UpdateCheckService.class);
    PendingIntent pi = PendingIntent.getService(ctx, 0, i, 0);
    Date lastCheck = prefs.getLastUpdateCheck();
    if (showDebugOutput)
        Log.d(TAG, "Last check on " + lastCheck.toString());
    cancelUpdateChecks(ctx);
    AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
    if (showDebugOutput)
        Log.d(TAG, "Setting alarm for UpdateService");
    am.setRepeating(AlarmManager.RTC_WAKEUP, lastCheck.getTime() + updateFrequency, updateFrequency, pi);
}
Example 8
Project: ARTPart-master  File: SignatureSpiTest.java View source code
public void testEngineGetParameters() {
    // or rather test that no UnsupportedOperationException is thrown?
    @SuppressWarnings("unused") Signature s = new Signature("dummy") {

        protected AlgorithmParameters engineGetParameters() {
            engineGetParametersCalled = true;
            try {
                super.engineGetParameters();
            } catch (UnsupportedOperationException e) {
                engineGetParametersExceptionOcurred = true;
            }
            return null;
        }

        @Override
        protected Object engineGetParameter(String param) throws InvalidParameterException {
            return null;
        }

        @Override
        protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
        }

        @Override
        protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
        }

        @Override
        protected void engineSetParameter(String param, Object value) throws InvalidParameterException {
        }

        @Override
        protected byte[] engineSign() throws SignatureException {
            return null;
        }

        @Override
        protected void engineUpdate(byte b) throws SignatureException {
        }

        @Override
        protected void engineUpdate(byte[] b, int off, int len) throws SignatureException {
        }

        @Override
        protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
            return false;
        }
    };
    // must call engineGetParameters
    s.getParameters();
    assertTrue(engineGetParametersCalled);
    assertTrue(engineGetParametersExceptionOcurred);
}
Example 9
Project: property-db-master  File: SignatureSpiTest.java View source code
public void testEngineGetParameters() {
    // or rather test that no UnsupportedOperationException is thrown?
    @SuppressWarnings("unused") Signature s = new Signature("dummy") {

        protected AlgorithmParameters engineGetParameters() {
            engineGetParametersCalled = true;
            try {
                super.engineGetParameters();
            } catch (UnsupportedOperationException e) {
                engineGetParametersExceptionOcurred = true;
            }
            return null;
        }

        @Override
        protected Object engineGetParameter(String param) throws InvalidParameterException {
            return null;
        }

        @Override
        protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
        }

        @Override
        protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
        }

        @Override
        protected void engineSetParameter(String param, Object value) throws InvalidParameterException {
        }

        @Override
        protected byte[] engineSign() throws SignatureException {
            return null;
        }

        @Override
        protected void engineUpdate(byte b) throws SignatureException {
        }

        @Override
        protected void engineUpdate(byte[] b, int off, int len) throws SignatureException {
        }

        @Override
        protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
            return false;
        }
    };
    // must call engineGetParameters
    s.getParameters();
    assertTrue(engineGetParametersCalled);
    assertTrue(engineGetParametersExceptionOcurred);
}
Example 10
Project: SMUpdater-master  File: StartupReceiver.java View source code
public static void scheduleUpdateService(Context ctx, int updateFrequency) {
    if (updateFrequency < 0)
        throw new InvalidParameterException("updateFrequency can't be negative");
    Preferences prefs = new Preferences(ctx);
    if (showDebugOutput)
        Log.d(TAG, "Scheduling alarm to go off every " + updateFrequency + " msegs");
    Intent i = new Intent(ctx, UpdateCheckService.class);
    PendingIntent pi = PendingIntent.getService(ctx, 0, i, 0);
    Date lastCheck = prefs.getLastUpdateCheck();
    if (showDebugOutput)
        Log.d(TAG, "Last check on " + lastCheck.toString());
    cancelUpdateChecks(ctx);
    AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
    if (showDebugOutput)
        Log.d(TAG, "Setting alarm for UpdateService");
    am.setRepeating(AlarmManager.RTC_WAKEUP, lastCheck.getTime() + updateFrequency, updateFrequency, pi);
}
Example 11
Project: warmupdater-master  File: StartupReceiver.java View source code
public static void scheduleUpdateService(Context ctx, int updateFrequency) {
    if (updateFrequency < 0)
        throw new InvalidParameterException("updateFrequency can't be negative");
    Preferences prefs = new Preferences(ctx);
    if (showDebugOutput)
        Log.d(TAG, "Scheduling alarm to go off every " + updateFrequency + " msegs");
    Intent i = new Intent(ctx, UpdateCheckService.class);
    PendingIntent pi = PendingIntent.getService(ctx, 0, i, 0);
    Date lastCheck = prefs.getLastUpdateCheck();
    if (showDebugOutput)
        Log.d(TAG, "Last check on " + lastCheck.toString());
    cancelUpdateChecks(ctx);
    AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
    if (showDebugOutput)
        Log.d(TAG, "Setting alarm for UpdateService");
    am.setRepeating(AlarmManager.RTC_WAKEUP, lastCheck.getTime() + updateFrequency, updateFrequency, pi);
}
Example 12
Project: jdkernel-updater-master  File: StartupReceiver.java View source code
public static void scheduleUpdateService(Context ctx, int updateFrequency) {
    if (updateFrequency < 0)
        throw new InvalidParameterException("updateFrequency can't be negative");
    Preferences prefs = new Preferences(ctx);
    if (showDebugOutput)
        Log.d(TAG, "Scheduling alarm to go off every " + updateFrequency + " msegs");
    Intent i = new Intent(ctx, UpdateCheckService.class);
    PendingIntent pi = PendingIntent.getService(ctx, 0, i, 0);
    Date lastCheck = prefs.getLastUpdateCheck();
    if (showDebugOutput)
        Log.d(TAG, "Last check on " + lastCheck.toString());
    cancelUpdateChecks(ctx);
    AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
    if (showDebugOutput)
        Log.d(TAG, "Setting alarm for UpdateService");
    am.setRepeating(AlarmManager.RTC_WAKEUP, lastCheck.getTime() + updateFrequency, updateFrequency, pi);
}
Example 13
Project: android-sdk-sources-for-api-level-23-master  File: SignatureSpiTest.java View source code
public void testEngineGetParameters() {
    // or rather test that no UnsupportedOperationException is thrown?
    @SuppressWarnings("unused") Signature s = new Signature("dummy") {

        protected AlgorithmParameters engineGetParameters() {
            engineGetParametersCalled = true;
            try {
                super.engineGetParameters();
            } catch (UnsupportedOperationException e) {
                engineGetParametersExceptionOcurred = true;
            }
            return null;
        }

        @Override
        protected Object engineGetParameter(String param) throws InvalidParameterException {
            return null;
        }

        @Override
        protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
        }

        @Override
        protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
        }

        @Override
        protected void engineSetParameter(String param, Object value) throws InvalidParameterException {
        }

        @Override
        protected byte[] engineSign() throws SignatureException {
            return null;
        }

        @Override
        protected void engineUpdate(byte b) throws SignatureException {
        }

        @Override
        protected void engineUpdate(byte[] b, int off, int len) throws SignatureException {
        }

        @Override
        protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
            return false;
        }
    };
    // must call engineGetParameters
    s.getParameters();
    assertTrue(engineGetParametersCalled);
    assertTrue(engineGetParametersExceptionOcurred);
}
Example 14
Project: deck_old-master  File: Card.java View source code
@Override
public int compare(Card card, Card card2) {
    if (card == null) {
        return -1;
    } else if (card2 == null) {
        return 1;
    }
    switch(mSortingType) {
        case SORT_BY_RANK:
            {
                int comp = compareRank(card, card2);
                if (comp != 0) {
                    return comp;
                } else {
                    return compareSuit(card, card2);
                }
            }
        case SORT_BY_SUIT:
            {
                int comp = compareSuit(card, card2);
                if (comp != 0) {
                    return comp;
                } else {
                    return compareRank(card, card2);
                }
            }
        case SORT_BY_CARD_NUMBER:
            {
                return compareCardNumber(card, card2);
            }
        default:
            {
                throw new InvalidParameterException("Invalid sorting type.");
            }
    }
}
Example 15
Project: MobileSensing-master  File: TestFileCompressor.java View source code
/**
   * Test method for
   * [email protected] [email protected]sor(de.unikassel.android.sdcframework.util.facade.CompressionStrategy)}
   * .
   */
public final void testFileCompressor() {
    try {
        new FileCompressor(null);
        fail("Expected InvalidParameterException exception");
    } catch (InvalidParameterException e) {
    } catch (Exception e) {
        fail("Unexpected exception type");
    }
    CompressionStrategy strategy = new ZipCompressionStrategy();
    FileCompressor compressor = new FileCompressor(strategy);
    assertNotNull("Expected strategy not null", compressor.getStrategy());
    assertEquals("Expected strategy set", strategy, compressor.getStrategy());
}
Example 16
Project: records-management-master  File: RecordsImpl.java View source code
@Override
public Node fileOrLinkRecord(String recordId, TargetContainer target, Parameters parameters) {
    ParameterCheck.mandatoryString("recordId", recordId);
    if ((target.getTargetParentId() == null || target.getTargetParentId().isEmpty()) && (target.getRelativePath() == null || target.getRelativePath().isEmpty())) {
        throw new InvalidParameterException("No target folder information was provided");
    }
    // Get record
    NodeRef record = nodes.validateNode(recordId);
    // Get record folder to file/link the record to
    String parentContainerId = target.getTargetParentId();
    if (parentContainerId == null || parentContainerId.isEmpty()) {
        // If target container not provided get fileplan
        parentContainerId = AuthenticationUtil.runAsSystem(new RunAsWork<String>() {

            @Override
            public String doWork() {
                return filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID).getId();
            }
        });
    }
    NodeRef parentRecordFolder = nodes.getOrCreatePath(parentContainerId, target.getRelativePath(), ContentModel.TYPE_CONTENT);
    // Check if the target is a record folder
    if (!dictionaryService.isSubClass(nodeService.getType(parentRecordFolder), RecordsManagementModel.TYPE_RECORD_FOLDER)) {
        throw new InvalidArgumentException("The provided target parent is not a record folder");
    }
    // Get the current parent type to decide if we link or move the record
    NodeRef primaryParent = nodeService.getPrimaryParent(record).getParentRef();
    if (dictionaryService.isSubClass(nodeService.getType(primaryParent), RecordsManagementModel.TYPE_RECORD_FOLDER)) {
        recordService.link(record, parentRecordFolder);
    } else {
        try {
            fileFolderService.moveFrom(record, primaryParent, parentRecordFolder, null);
        } catch (FileExistsException e) {
            throw new IntegrityException(e.getMessage(), null);
        } catch (FileNotFoundException e) {
            throw new ConcurrencyFailureException("The record was deleted while filing it", e);
        }
    }
    // Get the record info
    return nodes.getFolderOrDocument(recordId, parameters);
}
Example 17
Project: strongback-java-master  File: Parser.java View source code
/**
     * String based argument parser, syntax information and arguments that require a parameter are specified as strings. 
     * Does not handle any usage or help information, that should be printed elsewhere. Parses an array of GNU style command 
     * line arguments and populates a [email protected] Map}. Arguments without a parameter (flags) are mapped to null. Arguments 
     * that do have a parameter are mapped to that parameter.  
     * @param args arguments to parse
     * @param params a String list of arguments that require parameters [email protected] "abc"} means arguments a, b, and c all require parameters
     * @param syntax a String representing the syntax of the arguments. Each possible set of required arguments should be listed 
     *               separated by a [email protected] |}. Any arguments required to not be present should be preceded by a [email protected] !}. Any
     *               arguments not mentioned are assumed to always be valid. If the argument list does not meet this syntax, an
     *               [email protected] InvalidParameterException} is thrown.
     *               Example: [email protected] "abc|d!e|e!d|fgh"} - a, b, and c are required, or d is required and e cannot be present, and so on.
     * @return a [email protected] Map} mapping <[email protected] String}s to [email protected] String}s representing all of the command line arguments.
     */
public static Map<String, String> parse(String[] args, String params, String syntax) {
    Map<String, String> map = new HashMap<>();
    String lastArg = "";
    for (String arg : args) {
        if (arg.length() > 0) {
            if (arg.startsWith("-")) {
                if (arg.startsWith("--")) {
                // Hook for handling long options
                } else {
                    for (char c : arg.toCharArray()) {
                        lastArg = String.valueOf(c);
                        map.put(lastArg, null);
                    }
                }
            } else {
                map.put(lastArg, arg);
            }
        }
    }
    // Verify arguments have required parameters
    for (char key : params.toCharArray()) {
        if (map.containsKey(String.valueOf(key)) && map.get(String.valueOf(key)) == null)
            throw new InvalidParameterException("Missing parameter for argument: -" + key);
    }
    // Test syntax (pipe is a regex character)
    for (String req : syntax.split("\\|")) {
        boolean failed = false;
        for (int i = 0; i < req.length(); i++) {
            if (req.charAt(i) == '!') {
                // Failure if map contains the next character
                if (map.containsKey(String.valueOf(req.charAt(++i))))
                    failed = true;
            } else {
                // Failure if map doesn't contain this character
                if (!map.containsKey(String.valueOf(req.charAt(i))))
                    failed = true;
            }
        }
        if (!failed)
            return Collections.unmodifiableMap(map);
    }
    throw new InvalidParameterException("Bad syntax");
}
Example 18
Project: oobd-master  File: PSSSignatureSpi.java View source code
protected void engineSetParameter(AlgorithmParameterSpec params) throws InvalidParameterException {
    if (params instanceof PSSParameterSpec) {
        PSSParameterSpec newParamSpec = (PSSParameterSpec) params;
        if (originalSpec != null) {
            if (!DigestFactory.isSameDigest(originalSpec.getDigestAlgorithm(), newParamSpec.getDigestAlgorithm())) {
                throw new InvalidParameterException("parameter must be using " + originalSpec.getDigestAlgorithm());
            }
        }
        if (!newParamSpec.getMGFAlgorithm().equalsIgnoreCase("MGF1") && !newParamSpec.getMGFAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1.getId())) {
            throw new InvalidParameterException("unknown mask generation function specified");
        }
        if (!(newParamSpec.getMGFParameters() instanceof MGF1ParameterSpec)) {
            throw new InvalidParameterException("unkown MGF parameters");
        }
        MGF1ParameterSpec mgfParams = (MGF1ParameterSpec) newParamSpec.getMGFParameters();
        if (!DigestFactory.isSameDigest(mgfParams.getDigestAlgorithm(), newParamSpec.getDigestAlgorithm())) {
            throw new InvalidParameterException("digest algorithm for MGF should be the same as for PSS parameters.");
        }
        Digest newDigest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());
        if (newDigest == null) {
            throw new InvalidParameterException("no match on MGF digest algorithm: " + mgfParams.getDigestAlgorithm());
        }
        this.engineParams = null;
        this.paramSpec = newParamSpec;
        this.mgfDigest = newDigest;
        this.saltLength = paramSpec.getSaltLength();
        this.trailer = getTrailer(paramSpec.getTrailerField());
        setupContentDigest();
    } else {
        throw new InvalidParameterException("Only PSSParameterSpec supported");
    }
}
Example 19
Project: open-mika-master  File: JDKPSSSigner.java View source code
protected void engineSetParameter(AlgorithmParameterSpec params) throws InvalidParameterException {
    if (params instanceof PSSParameterSpec) {
        paramSpec = (PSSParameterSpec) params;
        if (originalSpec != null) {
            if (!JCEDigestUtil.isSameDigest(originalSpec.getDigestAlgorithm(), paramSpec.getDigestAlgorithm())) {
                throw new InvalidParameterException("parameter must be using " + originalSpec.getDigestAlgorithm());
            }
        }
        if (!paramSpec.getMGFAlgorithm().equalsIgnoreCase("MGF1") && !paramSpec.getMGFAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1.getId())) {
            throw new InvalidParameterException("unknown mask generation function specified");
        }
        if (!(paramSpec.getMGFParameters() instanceof MGF1ParameterSpec)) {
            throw new InvalidParameterException("unkown MGF parameters");
        }
        MGF1ParameterSpec mgfParams = (MGF1ParameterSpec) paramSpec.getMGFParameters();
        if (!JCEDigestUtil.isSameDigest(mgfParams.getDigestAlgorithm(), paramSpec.getDigestAlgorithm())) {
            throw new InvalidParameterException("digest algorithm for MGF should be the same as for PSS parameters.");
        }
        digest = JCEDigestUtil.getDigest(mgfParams.getDigestAlgorithm());
        if (digest == null) {
            throw new InvalidParameterException("no match on MGF digest algorithm: " + mgfParams.getDigestAlgorithm());
        }
        this.saltLength = paramSpec.getSaltLength();
        this.trailer = getTrailer(paramSpec.getTrailerField());
    } else {
        throw new InvalidParameterException("Only PSSParameterSpec supported");
    }
}
Example 20
Project: geotools-old-master  File: ProcessFunction.java View source code
public Object evaluate(Object object) {
    // collect the entries
    Map<String, Object> processInputs = new HashMap<String, Object>();
    for (Expression input : inputExpressions) {
        Object result = input.evaluate(object, Map.class);
        if (result != null) {
            Map map = (Map) result;
            if (map.size() > 1) {
                throw new InvalidParameterException("The parameters to a ProcessFunction " + "must all be maps with a single entry, " + "the key is the process argument name, " + "the value is the argument value");
            } else {
                // handle the key/value
                Iterator it = map.entrySet().iterator();
                Map.Entry<String, Object> entry = (Entry<String, Object>) it.next();
                final String paramName = entry.getKey();
                final Object paramValue = entry.getValue();
                // see if we have a parameter with that name
                Parameter param = parameters.get(paramName);
                if (param == null) {
                    throw new InvalidParameterException("Parameter " + paramName + " is not among the process parameters: " + parameters.keySet());
                } else {
                    // to the process invocation params
                    if (paramValue != null) {
                        Object converted;
                        if (param.maxOccurs > 1) {
                            // they have to deal with two conversions, from single to multi, from type to type
                            if (!(paramValue instanceof Collection) && !(paramValue.getClass().isArray())) {
                                List<Object> collection = Collections.singletonList(paramValue);
                                converted = Converters.convert(collection, Array.newInstance(param.type, 0).getClass());
                            } else {
                                converted = Converters.convert(paramValue, Array.newInstance(param.type, 0).getClass());
                            }
                        } else {
                            converted = Converters.convert(paramValue, param.type);
                        }
                        if (converted == null) {
                            if (param.maxOccurs > 1 && Collection.class.isAssignableFrom(paramValue.getClass())) {
                                final Collection collection = (Collection) paramValue;
                                Collection convertedCollection = new ArrayList(collection.size());
                                for (Object original : collection) {
                                    Object convertedItem = Converters.convert(original, param.type);
                                    if (original != null && convertedItem == null) {
                                        throw new InvalidParameterException("Could not convert the value " + original + " into the expected type " + param.type + " for parameter " + paramName);
                                    }
                                    convertedCollection.add(convertedItem);
                                }
                                Object array = Array.newInstance(param.type, convertedCollection.size());
                                int i = 0;
                                for (Object item : convertedCollection) {
                                    Array.set(array, i, item);
                                    i++;
                                }
                                converted = array;
                            } else {
                                throw new InvalidParameterException("Could not convert the value " + paramValue + " into the expected type " + param.type + " for parameter " + paramName);
                            }
                        }
                        processInputs.put(paramName, converted);
                    }
                }
            }
        }
    }
    // execute the process
    try {
        ExceptionProgressListener listener = new ExceptionProgressListener();
        Map<String, Object> results = process.execute(processInputs, listener);
        // report them to the listener
        if (listener.getExceptions().size() > 0) {
            // uh oh, an exception occurred during processing
            Throwable t = listener.getExceptions().get(0);
            throw new RuntimeException("Failed to evaluate process function, error is: " + t.getMessage(), t);
        }
        return getResult(results, processInputs);
    } catch (ProcessException e) {
        throw new RuntimeException("Failed to evaluate the process function, error is: " + e.getMessage(), e);
    }
}
Example 21
Project: JBossAS51-master  File: XMLScheduleProvider.java View source code
/**
    * Converts the given Data string to a date
    * where not value means 1/1/1970, "NOW" means
    * now (plus a second), an long value means time
    * in milliseconds since 1/1/1970 and a String is
    * a Date string which is intepreted by a Simple
    * Data Formatter.
    *
    * @param pStartDate the date
    * @param dateFormat the dateFormat, the locale is
    *        is used when null or blank
    */
protected Date getStartDate(String pStartDate, String dateFormat) {
    pStartDate = pStartDate == null ? "" : pStartDate.trim();
    Date lReturn = null;
    if (pStartDate.equals("")) {
        lReturn = new Date(0);
    } else if (pStartDate.equals("NOW")) {
        lReturn = new Date(new Date().getTime() + 1000);
    } else {
        try {
            long lDate = new Long(pStartDate).longValue();
            lReturn = new Date(lDate);
        } catch (Exception e) {
            try {
                SimpleDateFormat dateFormatter = null;
                if (dateFormat == null || dateFormat.trim().length() == 0)
                    dateFormatter = new SimpleDateFormat();
                else
                    dateFormatter = new SimpleDateFormat(dateFormat);
                lReturn = dateFormatter.parse(pStartDate);
            } catch (Exception e2) {
                log.error("Could not parse given date string: " + pStartDate, e2);
                throw new InvalidParameterException("Schedulable Date is not of correct format");
            }
        }
    }
    log.debug("Initial Start Date is set to: " + lReturn);
    return lReturn;
}
Example 22
Project: picard-tools-master  File: FormatUtil.java View source code
/**
     * Attempts to determine the correct parse method to call based on the desired
     * return type and then parses the String and returns the value.
     *
     * @param value the String value to be parsed
     * @param returnType the desired return type
     * @return an object of the returnType
     */
public Object parseObject(String value, Class<?> returnType) {
    if (returnType == Short.class || returnType == Short.TYPE)
        return parseShort(value);
    if (returnType == Integer.class || returnType == Integer.TYPE)
        return parseInt(value);
    if (returnType == Long.class || returnType == Long.TYPE)
        return parseLong(value);
    if (returnType == Float.class || returnType == Float.TYPE)
        return parseFloat(value);
    if (returnType == Double.class || returnType == Double.TYPE)
        return parseDouble(value);
    if (returnType == Boolean.class || returnType == Boolean.TYPE)
        return parseBoolean(value);
    if (returnType == Iso8601Date.class)
        return parseIso8601Date(value);
    if (returnType == Date.class)
        return parseDate(value);
    if (returnType == Byte.class || returnType == Byte.TYPE)
        return parseInt(value);
    if (returnType == File.class)
        return new File(value);
    if (Enum.class.isAssignableFrom(returnType))
        return parseEnum(value, (Class<? extends Enum>) returnType);
    if (returnType == String.class)
        return value;
    throw new InvalidParameterException("Don't know how to convert a String to a " + returnType.getName());
}
Example 23
Project: j2objc-master  File: SignatureSpiTest.java View source code
public void testEngineGetParameters() {
    // or rather test that no UnsupportedOperationException is thrown?
    @SuppressWarnings("unused") Signature s = new Signature("dummy") {

        protected AlgorithmParameters engineGetParameters() {
            engineGetParametersCalled = true;
            try {
                super.engineGetParameters();
            } catch (UnsupportedOperationException e) {
                engineGetParametersExceptionOcurred = true;
            }
            return null;
        }

        @Override
        protected Object engineGetParameter(String param) throws InvalidParameterException {
            return null;
        }

        @Override
        protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
        }

        @Override
        protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
        }

        @Override
        protected void engineSetParameter(String param, Object value) throws InvalidParameterException {
        }

        @Override
        protected byte[] engineSign() throws SignatureException {
            return null;
        }

        @Override
        protected void engineUpdate(byte b) throws SignatureException {
        }

        @Override
        protected void engineUpdate(byte[] b, int off, int len) throws SignatureException {
        }

        @Override
        protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
            return false;
        }
    };
    // must call engineGetParameters
    s.getParameters();
    assertTrue(engineGetParametersCalled);
    assertTrue(engineGetParametersExceptionOcurred);
}
Example 24
Project: JBossAS_5_1_EDG-master  File: XMLScheduleProvider.java View source code
/**
    * Converts the given Data string to a date
    * where not value means 1/1/1970, "NOW" means
    * now (plus a second), an long value means time
    * in milliseconds since 1/1/1970 and a String is
    * a Date string which is intepreted by a Simple
    * Data Formatter.
    *
    * @param pStartDate the date
    * @param dateFormat the dateFormat, the locale is
    *        is used when null or blank
    */
protected Date getStartDate(String pStartDate, String dateFormat) {
    pStartDate = pStartDate == null ? "" : pStartDate.trim();
    Date lReturn = null;
    if (pStartDate.equals("")) {
        lReturn = new Date(0);
    } else if (pStartDate.equals("NOW")) {
        lReturn = new Date(new Date().getTime() + 1000);
    } else {
        try {
            long lDate = new Long(pStartDate).longValue();
            lReturn = new Date(lDate);
        } catch (Exception e) {
            try {
                SimpleDateFormat dateFormatter = null;
                if (dateFormat == null || dateFormat.trim().length() == 0)
                    dateFormatter = new SimpleDateFormat();
                else
                    dateFormatter = new SimpleDateFormat(dateFormat);
                lReturn = dateFormatter.parse(pStartDate);
            } catch (Exception e2) {
                log.error("Could not parse given date string: " + pStartDate, e2);
                throw new InvalidParameterException("Schedulable Date is not of correct format");
            }
        }
    }
    log.debug("Initial Start Date is set to: " + lReturn);
    return lReturn;
}
Example 25
Project: openjdk8-jdk-master  File: DSAParameterGenerator.java View source code
/**
     * Initializes this parameter generator with a set of
     * algorithm-specific parameter generation values.
     *
     * @param genParamSpec the set of algorithm-specific parameter generation values
     * @param random the source of randomness
     *
     * @exception InvalidAlgorithmParameterException if the given parameter
     * generation values are inappropriate for this parameter generator
     */
protected void engineInit(AlgorithmParameterSpec genParamSpec, SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(genParamSpec instanceof DSAGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException("Invalid parameter");
    }
    DSAGenParameterSpec dsaGenParams = (DSAGenParameterSpec) genParamSpec;
    int primePLen = dsaGenParams.getPrimePLength();
    if (primePLen > 2048) {
        throw new InvalidParameterException("No support for prime size " + primePLen);
    }
    // directly initialize using the already validated values
    this.valueL = primePLen;
    this.valueN = dsaGenParams.getSubprimeQLength();
    this.seedLen = dsaGenParams.getSeedLength();
    this.random = random;
}